How to completely disable ViewState and ControlState
Here is a code snippet that will COMPLETELY disable ViewState and ControlState.
Please note, if you want to disable viewstate, you can set “EnableViewState” to false for the page, however you will still see “VIEWSTATE” in the page. The reason for that is because the hidden ViewState HTML field also contains “Control State”, which is used by server controls (either built in controls or custom 3rd party controls) and is not disable-able (for core functionality that their control depends on).
However you can still disable this, with disastrous consequences on postback.
USE THIS only if you have NO POSTBACKS whatsoever and you are living in a happy client side world of javascript and web service calls.
Put this following code inside your ASP.NET page
private class DummyPageStatePersisterageStatePersister { public DummyPageStatePersister(Page p) : base(p) { } public override void Load() { } public override void Save() { } } private DummyPageStatePersister _PageStatePersister; protected override PageStatePersister PageStatePersister { get { if (_PageStatePersister == null) _PageStatePersister = new DummyPageStatePersister(this); return _PageStatePersister; } }
Please note this will has disastrous consequences if you attempt to do a postback because you have essentially killed the control state.
Related Reading:
Other Interesting Posts
-
Articles
- January 2011
- April 2010
- March 2010
- February 2010
- January 2010
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- February 2009
- December 2008
- November 2008
- October 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
-
Meta







