views:

85

answers:

2

For some reason I have noticed that at run time when looking at my source of my ASP.NET page there are tags being created.

<input type="hidden" name="_VIEWSTATE" id="_viewstate" value="..lots of text.." />

and

<input type="hidden" name="_EVENTVALIDATION" id="_EVENTVALIDATION" value="..lots of text.." />
  1. Why is this and what is it for?
  2. How can I make sure that these are not created?

Thanks in advanced!

+1  A: 

Chances are that you don't want to get rid of either one of them.

_VIEWSTATE hidden field is used to store the encoded value of ASP.NET WebForms ViewState. If a normal WebForm-style development (as opposed to MVC) you use ViewState all the time when you do things like string someText = TextBox1.Text in your code behind; or when you execute a PostBack and all the textbox, checkbox, dropdown values are preserved without you having to do anything - that's all features of ViewState. It's very convenient and pretty much a standard practice for ASP.NET WebForms. You can disable ViewState per page using EnableViewState property inside the '@Page` directive. I would assume you don't want to do it, though as you will probably notice a lot of things not working all of a sudden.

_EVENTVALIDATION is part of ASP.NET Event Validation scheme - this also can be disabled in the @Page directive (I believe the property is EnableEventValidation) but I can't imagine why you'd want to do it.

Marek Karbarz
So you will agree by disabling these will alter the security of the page/site?
Etienne
Disabling this would most certainly affect the security of your pages.
Marek Karbarz
I managed to disable the EventValidation but I cant get rid of the EnableViewState and i have tried EnableViewState="false". Any idea why it is still showing up?
Etienne
+1  A: 

The _EVENTVALIDATION control validates postbacks to reduce the risk of unauthorized postback requests and callbacks. You can disable this by setting

<pages enableEventValidation="false"> 

setting in web.config (or setting

EnableEventValidation="false" in @Page directive) but is not recommended!

rip
Thanks, but how do i disable the ViewsState? I have tried these: ViewStateEncryptionMode="Never" EnableViewState="false" EnableViewStateMac="false" but they dont work...........
Etienne
You can't remove view state control completely in the current version of ASP.NET. I've heard that you have better control over view state in .NET 4.0 when this comes out - maybe you will be able to remove this completely in this version?
rip