Base class and session object

Discussion in 'ASP .Net' started by Frank Esser, Jun 21, 2005.

  1. Frank Esser

    Frank Esser Guest

    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)
    {
    ...
    }
    }
    Frank Esser, Jun 21, 2005
    #1
    1. Advertising

  2. Frank Esser

    Frank Esser Guest

    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" <> schrieb im Newsbeitrag
    news:...
    > 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)
    > {
    > ...
    > }
    > }
    >
    >
    >
    >
    >
    Frank Esser, Jun 21, 2005
    #2
    1. Advertising

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

    "Frank Esser" <> wrote in message
    news:...
    > 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)
    > {
    > ...
    > }
    > }
    >
    >
    >
    >
    >
    Kevin Spencer, Jun 21, 2005
    #3
  4. Oops! In that case, ignore my unnecessary response!

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

    "Frank Esser" <> wrote in message
    news:...
    > 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" <> schrieb im Newsbeitrag
    > news:...
    >> 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)
    >> {
    >> ...
    >> }
    >> }
    >>
    >>
    >>
    >>
    >>

    >
    >
    Kevin Spencer, Jun 21, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    554
    justanotherguy
    Dec 3, 2004
  2. Alf P. Steinbach
    Replies:
    6
    Views:
    525
    John Carson
    Sep 3, 2005
  3. DanielJohnson
    Replies:
    7
    Views:
    1,991
    James Kanze
    Jan 17, 2009
  4. Hicham Mouline
    Replies:
    1
    Views:
    570
    Victor Bazarov
    Apr 20, 2009
  5. Karan Rajput
    Replies:
    2
    Views:
    123
    Abinoam Jr.
    Dec 22, 2010
Loading...

Share This Page