I have the following code snippet
1) Page1.aspx.cs
protected void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//other code
Session["scdid"] = null;
//other code
}
}
//Submit button handler for this page
protected void submit_record(object sender, EventArgs e)
{
//other code
string sschd = (string) Session["scdid"];
if (Session["scdid"] != null)
{
//do this
}
else
{
//insert into the database table with the primary key as an identity column
//get the current value of the ident
//Store it in session created in Page load and initialized to null
Session["scdid"] = sid;
Response.Redirect("Page2.aspx?sid=" + sid + "");
}
}
The control now goes to Page2.
At Page2 I click the browser back button and come back to Page1
I click the submit button again in Page 1
It does not give a value for the session variable. It goes once again in the else clause and gives an unhandled exception
Why does not the session value persist? What can I do to keep the primary key value persist even after coming to the page using the back button?
Would be grateful for your answer. I am new to ASP.Net and earnestly seek your help.
Thanks in advance
Jayakumar