Is it possible to share functions across aspx.vb pages?

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

We have some session variables that need to be reset to their default values
at certain times throughout the application. Rather than repeating the code
on each page that requires it, is there a way to hold this server-side code
some place and have each page call it when necessary? I can already see
another "shared function" that will be used similarly down the road, so is
there a way to put all these shared functions into one file?

In classic ASP we used the <!-- #INCLUDE FILE="sharedfunctions.asp" -->
directive. Is there something similar in ASP.Net?

Thanks in advance,
Dan
 
hmmm...I kind of understand what you are saying and think it will work.

A couple of questions though

Does "yourPageClass" have to be another aspx.vb file? I only ask because
the corresponding aspx file would never be used.

Also, in the called function, would the submitted request.form data be
available?

Finally....what does IIRC mean?

Thanks,
Dan
 
You could create a class, which can do this. If you're using Visual Studio
..NET, do the following:

Right Click on the project, and choose Add -> Add Class. In the filename
box, type "Global.vb". The code in the class should look something like
this:


Namespace YourProjectNamespace
Class Global

Public Shared Sub ResetSessionVariables()
With System.Web.HttpContext.Current
.Item("MyFirstSessionVar") = String.Empty
.Item("MySecondSessionVar") = String.Empty
.Item("MyThirdSessionVar") = String.Empty
End With
End Sub


'You can add more shared functions here


End Class
End Namespace


You can then call this code from any of your ASPX pages, using
Global.ResetSessionVariables()

Hope this helps,

Mun
 
Istead of going through the head of calling you page class from other
pages...
just create a new class which have all the common functions...

create instance of that class wherever needed and use your funcitons...

hope that helps.....
 
There we go, that's what I was looking for.

Thanks,
Dan

Munsifali Rashid said:
You could create a class, which can do this. If you're using Visual Studio
.NET, do the following:

Right Click on the project, and choose Add -> Add Class. In the filename
box, type "Global.vb". The code in the class should look something like
this:


Namespace YourProjectNamespace
Class Global

Public Shared Sub ResetSessionVariables()
With System.Web.HttpContext.Current
.Item("MyFirstSessionVar") = String.Empty
.Item("MySecondSessionVar") = String.Empty
.Item("MyThirdSessionVar") = String.Empty
End With
End Sub


'You can add more shared functions here


End Class
End Namespace


You can then call this code from any of your ASPX pages, using
Global.ResetSessionVariables()

Hope this helps,

Mun
 
Back
Top