0

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
            GenerateOutput(itemId);
        }
        else
        {
            string savedValue = string.Empty;

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

            //-- Post Back From PDF Form
            ProcessReportAction(itemId);
        }

    }

Thanks in advnce

1
  • Did you ever get this working? Commented Mar 1, 2013 at 1:25

2 Answers 2

1

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

4
  • I tried that and got the same result.
    – Music Magi
    Commented Feb 25, 2013 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? Commented Feb 25, 2013 at 19:22
  • Do you have viewstate enabled on your page? Commented Feb 25, 2013 at 19:25
  • <%@Page EnableViewState="True" %> Commented Feb 25, 2013 at 19:38
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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