What is a ViewState? - ASP.NET

What is a ViewState?

- If a site happens to not maintain a ViewState, then if a user has entered some information in a large form with many input fields and the page is refreshes, then the values filled up in the form are lost.

- The same situation can also occur on submitting the form. If the validations return an error, the user has to refill the form.

- Thus, submitting a form clears up all form values as the site does not maintain any state called ViewState.

- In ASP .NET, the ViewState of a form is maintained with a built-in state management technique keeps the state of the controls during subsequent postbacks by a particular user.

- The ViewState indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a <form runat="server"> control.
<input type="hidden" name="__VIEWSTATE" value="CareerRide">

- The ViewState option can be disabled by including the directive <%@ Page EnableViewState="false"%> at the top of an .aspx page.

- If a ViewState of a certain control has to be disabled, then set EnableViewState="false".

What is ViewState? Explain its benefits and limitations.

Viewstate is used to maintain or retain values on postback. It helps in preserving a page. Viewstate is internally maintained as a hidden field in encrypted form along with a key.

Advantages:

1. No server resources.
2. Viewstate ensures security because it stores the data in encrypted format.
3. Viewstates are simple. They are used by enabling or disabling the viewstate properties.
4. It is based on the wish of developer that they want to implement it at the page level or at control level.

Disadvantages:

1. If large amount of data is stored on the page, then page load might cause a problem.
2. Does not track across pages. Viewstate information does not automatically transfer from page to page.

What is Viewstate?

Viewstate is the mechanism that automatically saves the values of the page's items just before rendering the page. It stores items added to a page’s ViewState property as hidden fields on the page.
What is the difference between src and Code-Behind?
What is the difference between src and Code-Behind? - With the ‘src’ attribute, the source code files are deployed and are compiled by the JIT as needed...
What is the difference between URL and URI?
What is the difference between URL and URI? - A URL (Uniform Resource Locator) is the address of some resource on the Web. A resource is nothing but a page of a site...
What is the Pre-Compilation feature of ASP.NET 2.0?
What is the Pre-Compilation feature of ASP.NET 2.0? - the pre-compilation feature is used with which an entire site is precompiled before it is made available to users...
Post your comment
Discussion Board
View state
Good answer.
Ravi 01-30-2013
Page LLifecycle and view state
Check this url.
http://daythoughts.in/
daily this is updating with latest questions and answers
Albert 10-3-2012