SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a button that will load a page that contains a PDF document that users can fill out and save. After the save is clicked, the page posts-back and there is code to save the changes. However, I'm not able to get the session to preserve the value after postback. I have it enabled on the site and in the web.config. When the button is initially clicked and the page with the PDF is loaded, the ItemId gets pulled from the query string and stored in the session state variable. The next the page posts-back is when the user clicks the button to save the PDF, but at this point, the session state gets reset and even gets assigned a new unique identifier. Does anyone know a way to prevent this from happening?

 protected void Page_Load(object sender, EventArgs e)
        itemId = Request.QueryString["ItemId"];

        if (Session["ItemId"] == null || Session["ItemId"] != itemId){
            //HttpContext.Current.Session["ItemId"] = itemId;
            Session["ItemId"] = itemId;

        if (!PostBackFromPDF())
            //-- Generate the pdf or display pre-existing message
            string savedValue = string.Empty;

            if (Session["ItemId"] != null)
                savedValue = Session["ItemId"].ToString();
                itemId = savedValue;

            //-- Post Back From PDF Form


Thanks in advnce

share|improve this question
Did you ever get this working? – Steve Lineberry Mar 1 '13 at 1:25

Ever thought of using the viewstate to store the itemid instead of the session state?

share|improve this answer
I tried that and got the same result. – Music Magi Feb 25 '13 at 19:20
So you are on the same page, and from page load to a post back the value stored in the viewstate didn't come back? – Steve Lineberry Feb 25 '13 at 19:22
Do you have viewstate enabled on your page? – Steve Lineberry Feb 25 '13 at 19:25
<%@Page EnableViewState="True" %> – Steve Lineberry Feb 25 '13 at 19:38

I did get this working, but it looks like it wasn't really a problem of session. We ended up setting the session in a different page and it worked.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.