views:

26

answers:

2

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.

+1  A: 

Hey,

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.

Brian
So the quote *"we cannot disable control state"* is completely true for a non-MVC application? It's not possible to get rid of `ControlState` even if I don't use ASP.NET controls?
MainMa
I have not seen anything anywhere that says you can, because that was its intent... you may want to try @Shrage's trick...
Brian
+1  A: 

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
    {
    }
Shrage Smilowitz
This will net yet eliminate the hidden fields, but they will all be completely empty. there is definitely a way to get rid of the hidden elements too, this is just what i could come up quickly
Shrage Smilowitz
Thanks, it's fine. I would be able to get rid of the tag itself, but it doesn't matter too much.
MainMa