Search code examples
asp.netviewstate

Does viewstate expire?


Let's say you have a aspx page that does not rely on session, but does rely on viewstate for persistance between postbacks.

If a user is accessing this page, and leaves for a long lunch, will viewstate still be valid when he returns?


Solution

  • No ViewState is kept as part of the PostBack process. You can, however, override the Page class's SavePageStateToPersistenceMedium() and LoadPageStateFromPersistenceMedium(), to implement that behavior if desired. For more information read Understanding the ASP.NET ViewState.

    Note that Page ViewState is stored in the Session so if your Session expires, the ViewState will be lost. I wouldn't say this is ViewState expiring, but yes, it will be destroyed after Session timeout.