Software to help you build a better store
SEARCH
December 20, 2006

Reduce ViewState Size In ASP.NET 2.0

Robert Boedigheimer showed how to move most of ViewState out of the __VIEWSTATE hidden input field and into Session using a PageAdapter. Peter Smulovics showed how to move the rest of ViewState (namely the ControlState) into Session using a base Page class and web.config. Here is how to do both with the PageAdapter.

Create a new class in the App_Code folder:

using System.Web.UI;

using System.Web.UI.Adapters;

 

public class PageStateAdapter : PageAdapter

{

    public override PageStatePersister GetStatePersister()

    {

        return new SessionPageStatePersister(this.Page);

    }

}

Create a new .browser file in the App_Browsers folder:

<browsers>

  <browser refID="Default">

    <controlAdapters>

      <adapter controlType="System.Web.UI.Page" adapterType="PageStateAdapter" />

    </controlAdapters>

    <capabilities>

      <capability name="requiresControlStateInSession" value="true" />

    </capabilities>

  </browser>

</browsers>

Done.

This site looks much better in a browser that supports current web standards, but it is accessible to any browser. Download one now This link is to a third party web site which will open in a new window

Some parts of this site will not work effectively on this older browser.
Please consider updating your browser This link is to a third party web site which will open in a new window

SSL