View State

  1. It’s of type StateBag and is used for storing state/data to be used in postback to the same web form.

  2. ViewState being hidden element in form tag rendered, its different for different clients & is submitted to the server only if the form is submitted or posted.

  3. ViewState is a collection of Key-Value pairs, where Key is of type String and Value is of type Object. But only those objects which are marked as Serializable can be stored in ViewState.

  4. ViewState cannot be programmed on the client in javascript because the value of it is encrypted before it is rendered to the browser.

  5. If ViewState of the page is disabled (<%@Page EnableViewState=”False”) than anything added to it is not retained.

    Example:1

    And the Code Behind:


    Example:2

    And the Code Behind: