Frage

I have a current problem where on one page, the Viewstate info is disappearing if we open a different page and do a few postbacks there, ie:

  1. Open ListPage, change form selected options and do postback
  2. Press button that opens AddPage on new Tab
  3. On AddPage, add several new entries doing several postbacks, close tab
  4. Go back to ListPage try to refresh the grid
  5. On ListPage, viewstate is empty

So if I have a property that is storing and getting it's value from viewstate, on step 5 is getting null from viewstate.

if (ViewState["Stuff"] == null)
    return MyObject.Default;
else
    return (MyObject)ViewState["Stuff"];

From my understanding viewstate history size is by default 9 ( <sessionPageState historySize="9" /> ) but I wasn't expecting this to be shared between different pages and don't want to change this value.

I can go around the properties stored by storing them in session with a Guid generated per page, but the form controls and anything that got it's value from the database needs to be re-setted.

Is there any way to make the viewstate history independent between tabs/windows? Or any idea how to go around it?

I'm using Telerik controls on each page if that helps.

Edit: this explanation helped me understand how exactly the viewstate info is stored in session and how sessionPageState configuration affects it.

War es hilfreich?

Lösung

Found out what was happening,

By default the Pages are storing the ViewState in Session, ie, using the System.Web.UI.SessionPageStatePersister. Knowing this, then the observed behaviour is normal. It only stores a certain amount of page states (postbacks) and for every postback, the older info get lost, no matter in which tab/page the postback is being made of, as long as it's in the same session.

I added this to my pages to tell it to store the ViewState in the page itself, in an hidden field. That was already what I assumed it was happening.

protected override PageStatePersister PageStatePersister
{
    get
    {
        return new HiddenFieldPageStatePersister(this);
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top