?
Solved

calling a global function from .aspx page

Posted on 2004-04-16
13
Medium Priority
?
1,514 Views
Last Modified: 2008-02-01
I have a vb.net function that is declared in the global module. It is working fine when I call it from .aspx.vb code behind file but when I call it directly from .aspx page it gives me an error saying that the function is not declared. If I move the function to the code behind file it works. What do I do to be able to call a function declared in the global module from asp.net page (.aspx page)?

Here is my function call:

<TD><% # GetMenu()%></TD>
0
Comment
Question by:YZlat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 20

Expert Comment

by:ihenry
ID: 10844154
Hi YZlat,

the syntax <%# %> is used for data-bound control, you can use asp render block syntax instead

<TD><% GetMenu()%></TD>
0
 

Expert Comment

by:fatihdurgut
ID: 10848746
create a public variable in codebehind,
and call the function and set the return value to this variable
and then use this variable in aspx.
0
 
LVL 35

Author Comment

by:YZlat
ID: 10859583
ihenry, I tried using your solution before, but I still have to put my function in code behind instead of a module. If I keep it only in the module, I get an error that the function is not declared.

 fatihdurgut, I cannot call my function from code behind by setting a variable with a return value from that function because the function contains a lot of response.write statements.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Expert Comment

by:fatihdurgut
ID: 10866002
if this function includes html output, then make it  a user control
0
 
LVL 20

Expert Comment

by:ihenry
ID: 10866130
I didn't read the question carefully, sorry.

That should be namespacing problem. When you create a module, by default the class will looks something like this,

    Public Module GlobalModule
        Public Function ReturnZero() As Integer
            Return 0
        End Function
    End Module

You must call the function from aspx file with full qualified name syntax,

   <%= RootNamespace.GlobalModule.ReturnZero() %>

Where RootNamespace is the root namespace or by default same as project name.
0
 
LVL 35

Author Comment

by:YZlat
ID: 10868744
ihenry, the following

 <%= RootNamespace.GlobalModule.ReturnZero() %>

gives me an error

 RootNamespace.GlobalModule is not accessible in this context because it is 'Private'.

0
 
LVL 20

Expert Comment

by:ihenry
ID: 10869082
:) YZlat,

Sorry if I wasn't being so clear, what I mean by "RootNamespace" here is the default namespace used by your project, or do the following:
1. In Solution Explorer, right click on the target project
2. Select Properties to open the project property page
3. Under the "Common Properties / General" there's a textbox for the project default root Namespace or if you never make any change to it, it has the same name with your project.

For example your project name is "Project1" the default namespace then is also "Project1". Again you can call any public function in a global module class with full qualified name.

<%= Project1.GlobalModule.ReturnZero() %>

Hope this time is clear enough.
0
 
LVL 35

Author Comment

by:YZlat
ID: 10869989
No, that part I got. But when I did as you suggested, I got an error.

I wrote Project1.ModuleName.Function()

and got an error: 'Project1.ModuleName' is not accessible in this context because it is 'Private'.
0
 
LVL 20

Expert Comment

by:ihenry
ID: 10870006
Did you declare the module class as private?
0
 
LVL 20

Expert Comment

by:ihenry
ID: 10870038
Or the function as private? coz i have the similar code and it works just fine.
0
 
LVL 35

Author Comment

by:YZlat
ID: 10870670
no. here is my module declaration:

Module GlobalModule

End Module
0
 
LVL 20

Accepted Solution

by:
ihenry earned 400 total points
ID: 10870734
That is the problem, declare as public explicitly, like this

    Public Module GlobalModule

    End Module
0
 
LVL 35

Author Comment

by:YZlat
ID: 10870967
thank you so much
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question