views:

704

answers:

2

I would like to remove these hidden fields in my ASP.NET pages. Alternatively change the names or make sure the server code ignores them.

(I know I will loose some functionality, but I think it is better to handle it than removing 'runat=server'. The only thing I am worried about is Updatepanel, which i really need)

(The above is complete, further background is here )

A: 

You have not mentioned what exactly it is about ViewState that is bothering you and why you want to ignore the field, so it is difficult to provide a better solution without understanding the context of the problem.

You can disable ViewState at the page level by setting the EnableViewState attribute of the Page directive to false.

<%@ Page enableViewState="false" %>

Alternatively, you can turn off ViewState for Server controls by setting the respective control's EnableViewState property to false.

Cerebrus
AFAIK, some server controls choose to ignore this and use ViewState anyway.
Jakob Christensen
Yes - I think I have tried this already, and it is also the other __animals (underscore animals :-)
Olav
@Jakob: I think you're quite right. As teedyay mentions in his answer, you cannot turn it off completely without a major hack.
Cerebrus
+1  A: 

As far as I'm aware, you can't get rid of the ViewState altogether - i.e. you can't get rid of that hidden input field called __VIEWSTATE.

Controls can still access the ControlState when the ViewState is disabled. The ControlState is actually stored within the ViewState, so it winds up in the __VIEWSTATE hidden field.

Thus turning off the ViewState for the whole page will only make this hidden field smaller - it won't get rid of it altogether.

I believe .NET puts a small amount of its own secret information in there too, so if you really hack it and override how the page renders to get rid of this hidden field altogether, you'll probably find that your site stops working.

teedyay