Introduction
The stateless behaviour of HTTP makes it impossible to restore the form control values once a request is sent to the server. In ASP this was a major problem and we have to write code to overcome this problem. But in .NET it is handled by the page viewstate. So now in .NET the server retains the information about the previous client request, such as form fields and the state of the instantiated object.
The viewstate retains the value of most controls except the TextBox for accepting passwords, which doesn’t have this facility. The values are stored as name-value string variables, which are passed back to the client in the page. Since the client is not aware of the viewstate this is stored as a hidden field in the form. If you see the source for this page, you can see an input tag for which the type attribute is set to hidden followed by the name attribute and the value attribute. The value attribute is a string, which is not in a human readable format and is a combination of all values in controls. So when the page is sent back to the server the web processor reads this value and restores it in the server controls. Thus the state of the page is kept with the page itself rather than managing it in the web server. But you have to consider the performance issue in this case, as the time required to process the request is no more the same as when you don’t retain the value.
The viewstate is enabled by default for all the server controls. The viewstate can be disabled in four ways. You can disable it machine level, application level, page level and control level.
To disable it in the entire page
<%@ Page EnableViewState =”False” %>
To disable it in application level, use web.config
To disable it in control level, change the control properties