What goes in ViewState when page EnableViewState property is set to false?

I bet that many of you sow that the __viewstate filed still holding data even if all page controls and the page itself EnableViewState property set to false. Well, what’s going on, what is saved by the page in the ViewState although we turn ViewSate off?

To answer this question lets check what value is being saved in ViewState and what he stands for. We will start by overriding SavePageStateToPersistenceMedium method that responsible for saving the ViewState data to persist media (hidden field as default). This method gets an object parameter that is actually Triplet object. Triplet class holds three objects that can be added together to an ASP.NET server control's view state in hierarchical order. For the simplicity of that demonstration let’s talk about a page without any controls that we set it EnableViewState property to false. In this case the triplet object will hold value just in the First member. The First member holds a number, remember that number and continue the page process.

After getting the value preserved in the view state lets see what he means. To do so I’ll use stuffs that I described in “Behind the scenes of ASPX files”. Check the page XML file for it random key and open the RandomKey.cs file. Look for the GetTypeHashCode method in the cs file and you will find that it’s the same number that the page preserve to ViewState. To be more accurate this number is hash code that is unique to the Page object's control hierarchy.

1 Comment

Comments have been disabled for this content.