Session being lost in a simple test webpage
-
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 -
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. ThanksWhat 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.
-
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.
-
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. ThanksBased 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
-
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
-
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. ThanksTry putting the following line in Web.config under the System.Web: "sessionState mode="InProc" timeout="30" cookieless="false" /sessionState" Lemme know if it worked !