DTaylorAtWork
Technical User
I am having some issues with the site I'm working on right now. It's all aspx with c# codebehind.
Most of the pages have objects of classes I have created. Those objects were becoming null on every post back so I started loading them into session variables on page_unload and then reloading them from those session variables on page_load. It looks something like this:
Now this is working, to some extent but I've just noticed that when I leave the page, or hit refresh on my browser those session variables remain so that when I return the variables get repopulated but the page is back to it's starting position.
This of course causes a problem when I start using the form with the assumption that the objects have been reset.
Is there an event that fires only when a page is navigating to a new page? That way I can clean up the session to reclaim the memory and avoid improper object values?
I'm also open to suggestions of better ways to keep the objects in the proper state without declaring them static (which causes every user to mess with the same variable and causes any number of problems).
Thanks,
Dave
Most of the pages have objects of classes I have created. Those objects were becoming null on every post back so I started loading them into session variables on page_unload and then reloading them from those session variables on page_load. It looks something like this:
Code:
private myClass var1;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["load"] != null)
{
var1 = (myClass)Session["var1"];
Session.Remove("load");
}
}
protected void Page_Unload(object sender, EventArgs e)
{
if (Session["load"] == null)
{
Session["var1"] = var1;
Session["load"] = true;
}
}
Now this is working, to some extent but I've just noticed that when I leave the page, or hit refresh on my browser those session variables remain so that when I return the variables get repopulated but the page is back to it's starting position.
This of course causes a problem when I start using the form with the assumption that the objects have been reset.
Is there an event that fires only when a page is navigating to a new page? That way I can clean up the session to reclaim the memory and avoid improper object values?
I'm also open to suggestions of better ways to keep the objects in the proper state without declaring them static (which causes every user to mess with the same variable and causes any number of problems).
Thanks,
Dave