Accessing functions defined in Global.asax

A

Anjali Lourda

Hi,
I have defined a function in global.asax file. Could somebody please
tell me how i am supposed to call that function from the other files
of the same project.
Global.asax
public function getName() as String
dim name as string
name = "Abc"
return name
end function


myfile01.aspx
'How do I call that function from this file. Am I supposed to import
something?


Thanks in advance for this help
Anjali
 
R

Ranjan Rai

You can get a reference to the class and call the methods.By default the
class in Global.asax is named Global

Example:

Dim objGlobal as Global=New Global()

Dim strResult as string= objGlobal.getName()

If u wish to avoid making instance of the class u can define getName as a
static function
 
J

Janaka

Hi Anjali,

If your going to make global functions available to your application its
probably better to consolidate all your code into a DLL, stick it in your
/bin directory, and then reference it from your ASP.NET pages.
 
R

Ryan Walberg

Anjali said:
Hi,
I have defined a function in global.asax file. Could somebody please
tell me how i am supposed to call that function from the other files
of the same project.
Global.asax
public function getName() as String
dim name as string
name = "Abc"
return name
end function


myfile01.aspx
'How do I call that function from this file. Am I supposed to import
something?

You could call a function defined in global.asax but you would be *much*
better off creating a class with a static method and referencing the
method that way. This is the purpose of code-behind.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top