Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

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

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.