Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Session being lost in a simple test webpage

Session being lost in a simple test webpage

Scheduled Pinned Locked Moved ASP.NET
csharphelpvisual-studiowindows-admin
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jpegny
    wrote on last edited by
    #1

    Hi, I'm using visual studio 2008 and it's built in development webserver, with C# as the codebehind language. I'm trying to make a simple webapp in which you click a button which sets a session var (that part is working) and in the pageload i'm checking to see if it's a postback and if the session is not null. problem is that every time the session is null. I have done this successfully before with visual studio 2003 and on IIS. Here is the relevant code: protected void Button1_Click(object sender, EventArgs e) { Session["testvar"] = 25; /* if (Session["testvar"] == null) Response.Write("s is null"); else Response.Write("s is NOT null"); */ } protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { int x; //x = (int)Session["testvar"]; if (Session["testvar"] == null) Response.Write("test var is null"); else { x = (int)Session["testvar"]; TextBox1.Text = x.ToString(); } } } Any help is appreciated. Thanks

    A S P 3 Replies Last reply
    0
    • J jpegny

      Hi, I'm using visual studio 2008 and it's built in development webserver, with C# as the codebehind language. I'm trying to make a simple webapp in which you click a button which sets a session var (that part is working) and in the pageload i'm checking to see if it's a postback and if the session is not null. problem is that every time the session is null. I have done this successfully before with visual studio 2003 and on IIS. Here is the relevant code: protected void Button1_Click(object sender, EventArgs e) { Session["testvar"] = 25; /* if (Session["testvar"] == null) Response.Write("s is null"); else Response.Write("s is NOT null"); */ } protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { int x; //x = (int)Session["testvar"]; if (Session["testvar"] == null) Response.Write("test var is null"); else { x = (int)Session["testvar"]; TextBox1.Text = x.ToString(); } } } Any help is appreciated. Thanks

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      What session mode is selected in web.config ? What is the session timeout time ?

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      J 1 Reply Last reply
      0
      • A Abhijit Jana

        What session mode is selected in web.config ? What is the session timeout time ?

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        J Offline
        J Offline
        jpegny
        wrote on last edited by
        #3

        I've haven't set either of those, everything is left to default in web.config, the only thing I enabled was debugging. From my readings the default of inProc should be sufficient.

        1 Reply Last reply
        0
        • J jpegny

          Hi, I'm using visual studio 2008 and it's built in development webserver, with C# as the codebehind language. I'm trying to make a simple webapp in which you click a button which sets a session var (that part is working) and in the pageload i'm checking to see if it's a postback and if the session is not null. problem is that every time the session is null. I have done this successfully before with visual studio 2003 and on IIS. Here is the relevant code: protected void Button1_Click(object sender, EventArgs e) { Session["testvar"] = 25; /* if (Session["testvar"] == null) Response.Write("s is null"); else Response.Write("s is NOT null"); */ } protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { int x; //x = (int)Session["testvar"]; if (Session["testvar"] == null) Response.Write("test var is null"); else { x = (int)Session["testvar"]; TextBox1.Text = x.ToString(); } } } Any help is appreciated. Thanks

          S Offline
          S Offline
          Sir Dot Net
          wrote on last edited by
          #4

          Based on the code above, you have to click the button twice in order for the session var to show in the textbox. this is because the execution goes in this order: Page Load --You click Button Page Load Button Click

          J 1 Reply Last reply
          0
          • S Sir Dot Net

            Based on the code above, you have to click the button twice in order for the session var to show in the textbox. this is because the execution goes in this order: Page Load --You click Button Page Load Button Click

            J Offline
            J Offline
            jpegny
            wrote on last edited by
            #5

            Yes that was it. I ended up using the prerender event. Thanks

            1 Reply Last reply
            0
            • J jpegny

              Hi, I'm using visual studio 2008 and it's built in development webserver, with C# as the codebehind language. I'm trying to make a simple webapp in which you click a button which sets a session var (that part is working) and in the pageload i'm checking to see if it's a postback and if the session is not null. problem is that every time the session is null. I have done this successfully before with visual studio 2003 and on IIS. Here is the relevant code: protected void Button1_Click(object sender, EventArgs e) { Session["testvar"] = 25; /* if (Session["testvar"] == null) Response.Write("s is null"); else Response.Write("s is NOT null"); */ } protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { int x; //x = (int)Session["testvar"]; if (Session["testvar"] == null) Response.Write("test var is null"); else { x = (int)Session["testvar"]; TextBox1.Text = x.ToString(); } } } Any help is appreciated. Thanks

              P Offline
              P Offline
              pd69
              wrote on last edited by
              #6

              Try putting the following line in Web.config under the System.Web: "sessionState mode="InProc" timeout="30" cookieless="false" /sessionState" Lemme know if it worked !

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups