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

Jayakumar,
Use the debugger and check where the session object is losing its value...

Unnecessary quote removed

Jayakumar,
Use the debugger and check where the session object is losing its value...

I dont have a debugger in my editor. However I tried debugging the code for the session value using Response.Write to print the session value and using Response.End() immediately after. The value of the session variable is nothing. In the web.config I have entered session state as Inproc and timeout as 20 minutes.

Hope this helps in advising me suitably.

Thanks and regards

Jayakumar

Hi
The seesion variable value is available when I read it in the Page Load of the next aspx page. But when I use the back button to navigate back to the page and check the value it shows blank. Can anyone help me now?

Thanks in advance

Jayakumar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.