Accessing functions defined in Global.asax

  • Thread starter Thread starter Anjali Lourda
  • Start date Start date
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
 
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
 
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.
 
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.
 
Back
Top