Base class and session object

  • Thread starter Thread starter Frank Esser
  • Start date Start date
F

Frank Esser

Hi,

I created a base class for my project from that all other pages inherit.

Within this page in the OnLoad event I set some session object variables.

My intention is that first of all the OnLoad event is fired on each page
load and then the specific Page_Load event of the specific page.

But whenever the OnLoad event in the base class is fired the Session object
is empty again.

What am I doing wrong?

Here is my code:

public class MyBasePage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

protected override void OnLoad(EventArgs e)
{
// on each page load make sure that everything is available
if (Session["test"] == null) Session["test"] = "Just a test";
// calls the page specific OnLoad event
base.OnLoad(e);
}
}


public class WebForm1 : MyBasePage
{
private void Page_Load(object sender, System.EventArgs e)
{
...
}
}
 
Ok, it was my fault !
Somewhere in my code I set the session object to NULL and this was the
problem...
Sorry for my unnecessary request!
 
Are you by any chance testing this in the debugger of Visual Studio.Net?
This causes the app to restart every time you run it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
Oops! In that case, ignore my unnecessary response!

--
Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

Frank Esser said:
Ok, it was my fault !
Somewhere in my code I set the session object to NULL and this was the
problem...
Sorry for my unnecessary request!


Frank Esser said:
Hi,

I created a base class for my project from that all other pages inherit.

Within this page in the OnLoad event I set some session object variables.

My intention is that first of all the OnLoad event is fired on each page
load and then the specific Page_Load event of the specific page.

But whenever the OnLoad event in the base class is fired the Session
object is empty again.

What am I doing wrong?

Here is my code:

public class MyBasePage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

protected override void OnLoad(EventArgs e)
{
// on each page load make sure that everything is available
if (Session["test"] == null) Session["test"] = "Just a test";
// calls the page specific OnLoad event
base.OnLoad(e);
}
}


public class WebForm1 : MyBasePage
{
private void Page_Load(object sender, System.EventArgs e)
{
...
}
}
 

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

Back
Top