Tuesday, 14 October 2008


So I use SessionPageStatePersister in one of my project to keep ViewState to a minimum.

This really is a great class and great technique especially when dealing with developing countries.

The downside is that strange things can occur with this (especially if you use popups).

The Scenario

So lets say I do something with my page, launch a popup, within the popup, load 9 different pages, and then return to my original page.

What happens? I suddenly find my ViewState is trashed?

Why is my ViewState trashed?

If we reflect SessionPageStatePersister we will find there is a statement with the following condition:

&& (Count > 9)

Which will then dequeue and remove the viewstate item from the session, effectively trashing my viewstate for that page.

So how do I fix this?

In your web.config under system.web you need to add the following:

<sessionPageState historySize="100" /> (or whatever number you like)

The following MSDN page should help you out:


No comments: