You can disable viewstate on an ASP .NET 2.0 website by setting the enabledViewState=”false” on the configuration > system.web > pages node in the Web.config:

pages enableViewState="false">

Then you will have to fill dropdownlists etc. on every page postback in the OnInit event of the page and some times have to use the good old: this.Request.Form

selectedValue = this.Request.Form["ctl00$MainContentPlaceHolder$selectBatchDropDownList"];
The "ctl00$MainContentPlaceHolder$selectBatchDropDownList"  is the control UniqueID (selectedBatchDropDownList.UniqueID)

However, after reading some articles:

I re-enabled ViewState and started filling dropdownlists on the page “OnInit” event and saved the viewstate in the sessionstate.
This allowed me to use the normal code and reduced the viewstate size to 50 characters.

To persist viewstate to sessionstate use:

        /// <summary>
        /// Set viewstate to sessionstate
        /// </summary>
        protected override PageStatePersister PageStatePersister
                return new SessionPageStatePersister(this);

In the web.config


To completely remove viewstate information use:

/// <summary>
        /// Completly disable viewstate for performance
        /// </summary>
        /// <param name="viewState"></param>
        protected override void SavePageStateToPersistenceMedium(object viewState)
        /// <summary>
        /// Completly disable viewstate  for performance
        /// </summary>
        /// <returns></returns>
        protected override object LoadPageStateFromPersistenceMedium()
            return null;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts