• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1522
  • Last Modified:

calling a global function from .aspx page

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
YZlat
Asked:
YZlat
  • 6
  • 5
  • 2
1 Solution
 
ihenryCommented:
Hi YZlat,

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

<TD><% GetMenu()%></TD>
0
 
fatihdurgutCommented:
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
 
YZlatAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
fatihdurgutCommented:
if this function includes html output, then make it  a user control
0
 
ihenryCommented:
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
 
YZlatAuthor Commented:
ihenry, the following

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

gives me an error

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

0
 
ihenryCommented:
:) 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
 
YZlatAuthor Commented:
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
 
ihenryCommented:
Did you declare the module class as private?
0
 
ihenryCommented:
Or the function as private? coz i have the similar code and it works just fine.
0
 
YZlatAuthor Commented:
no. here is my module declaration:

Module GlobalModule

End Module
0
 
ihenryCommented:
That is the problem, declare as public explicitly, like this

    Public Module GlobalModule

    End Module
0
 
YZlatAuthor Commented:
thank you so much
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now