4
Reply

what is view state in asp.net?

Mohd Shahab

Mohd Shahab

13y
6.6k
0
Reply

    View state is a mechanism of the ASP.net to persist the state of web forms i.e. web control during the postbacks. View State uses the hidden fields to do the same.


    http://kalitinterviewquestions.blogspot.com/

    ViewState is a client side state management tool,which can contain information in the form of object.If information is stored in a viewstate,that information will be retained in roundtrip(Browser ->Server ->Browser)

    ViewState is the mechanism that allows state values to be preserved across page postbacks.

    Because of the stateless nature of web pages, regular page member variables will not maintain their values across postbacks.  When we need a page variable to maintain its value across page post backs, we can use ViewState to store that value.  Values stored in ViewState will be serialized and sent to the client browser as the value of a hidden form input.  When you view the page source (in your browser) of a page the uses ViewState, you may see this hidden viewstate input which will look something like this:

    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTM1ODM3Nj......." /> 

    This single hidden field contains all the viewstate values for all the page controls. This is an important aspect of viewstate that you need to consider. 

    Because viewstate is (by default) sent to the client browser and then returned to the server in the form of a hidden input control on your page, storing a significant amount of data in viewstate can increase your page size and can affect your page performance.

    To disable ViewState for a control, you can set the EnableViewState property to false.  When ViewState is disabled for any control, it will also automatically be disabled for all child controls of that control. 

    Example:

    View state is a method to store value (property) of page and controls on same page between  post back. By default each control view state enabled.