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

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
 
D

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
 
M

Munsifali Rashid

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
 
H

Hermit Dave

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.....
 
D

Dan

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top