Arseni Mourzenko
Arseni Mourzenko

Reputation: 52321

How to disable ControlState in ASP.NET?

How to completely disable ControlState in an ASP.NET website application to get rid of <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/ACBDEFGH...XYZ=" /> on every page?

Searching for a solution, I only found meaningless answers making no difference between ControlState and ViewState, or replies saying that "we cannot disable control state". The second assumption seems to be false, since StackOverflow pages do not have ViewState hidden field.

Upvotes: 2

Views: 1593

Answers (2)

Shrage Smilowitz
Shrage Smilowitz

Reputation: 25162

Create a custom class

 public class PageBase:Page
    {

        protected override void SavePageStateToPersistenceMedium(object state)
        {
                // Do nothing here
        }    

    }

Then change your page to inherit from PageBase

    public partial class Test : PageBase
    {
    }

Upvotes: 3

Brian Mains
Brian Mains

Reputation: 50728

yes, control state was meant to be a mechanism that would work even if view state was disabled, thus, its a permanent fixture of ASP.NET web forms. MVC would not have this since it doesn't utilize the viewstate or control state mechanism.

HTH.

Upvotes: 1

Related Questions