View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique. View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used during a post-back.
For Example of the login form
After the Submit button is clicked the value of user name and password is submitted to the server. We cannot restore the value again because after the postback the instance of the control is destroyed and on clicking of the Restore Button the server takes a new request and the server cannot restore the value of the TextBox.
After clicking on the Submit Button the value of user name and password is submitted in View State and the View State stores the value of user name and password during post-back.
After click on the Restore Button we can get the value again. The Value must be retained during post-back and the values are stored into a base 64 encoded string and this information is then put into the View State Hidden Field.
Data Objects That Can be Stored in View state- String
- Boolean Value
- Array Object
- Array List Object
- Hash Table
- Custom type Converters