How to load a class only once in a C# asp.net Page?

Pudele J

New member
the issue is I am at this level

public partial class _Default : System.Web.UI.Page
{

then i have a class from a library defined under this line.
classname variableName = new ClassName();

i want to make this load once.
and there is no way for me to call the this instance inside of page load or anything. how would i define this once and only once.. the instance i am using sets a connection and then i have to use different things from that library to send a message
This is under the page load class its the only place i can call this class without the rest of the application crashing. I've tried putting it in the page laod and that gives an error
 
I don't understand your question but this might help

if u want to instantiate the object once
if (!ispostback)
{
classname variableName = new ClassName();
}
and add it to your page load
or if you want to instantiate it once in the whole session
make a session in the page load of your master page
and before creating the object check if the session already exists or not
if it doesn't create it. this way u create it only once, and it's available to all your pages
 
Back
Top