What is ViewState

What is ViewState

What is ViewState?

ViewState is a built-in state management technique in ASP.Net. Its purpose is to keep the state of controls during subsequent postbacks by the same user. ViewState is implemented as a hidden element in the page with a name "_VIEWSTATE" and the value of the element is generated by using 128 bit encryption which contains the information about the states of various controls of the page.

The advantages of using ViewState are:
a) No server resources required. The view state is contained in a structure within the page code.
b) Simple implementation
c) Automatic retention of page and control state.
d) Enhanced Security features.

The disadvantages of using the ViewState are:
a) Performance: Because the view state is stored in the page itself, storing large values can cause the page to slow down the users display it and when they post it.
b) Security: The ViewState is stored in a hidden field on the page. Although ViewState stores data in hashed format, it can be tampered with.

Thanks & Regards
Paritosh Mohapatra


Author: Santosh Kumar Singh20 May 2010 Member Level: Gold   Points : 2

ASP.NET view state is a great feature and an essential tool for web development of today. It maintains the state of a page as it travels back and forth. There is no more need to worry about restoring values of page controls between postbacks.

There are some common misconceptions about ViewState. Let me discuss these points here for the benefit of the readers. ViewState does not hold the controls, rather it holds the values of the form controls and their corresponding ID's that would otherwise be lost due to a post back because they do not post with the form. ViewState is not used to hold session data or to transmit data between pages. ViewState does not recreate the dynamically created controls of a page. It does not restore the values to the controls after a post back operation. Taken aback? Yes, it is true. Even when the ViewState for a control is disabled, still the value would be retained after a post back of the page occurs, for input controls like TextBox or DropDownList. So then, what is ViewState? ViewState represents the state of a page when it was last processed on the web server. It holds the values of a control that has been dynamically changed

Author: Mayur14 Oct 2010 Member Level: Gold   Points : 1

ViewState is one type of state maintain variable.

It is use for storing information on page.

It is stored inforamation on client side, means stored at page level.

It's state will maintain in between postback event of the page.


Viewstate is stored at pagelevel. so whenever no of viewstate in a page is increase than time of page load is increase.

And store minimal information in viewstate.

Author: Amit Shah14 Oct 2010 Member Level: Gold   Points : 1


View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips. When the HTML markup for the page is rendered, the current state of the page and values that must be retained during postback are serialized into base64-encoded strings. This information is then put into the view state hidden field or fields.

View state is a repository in an ASP.NET page that can store values that have to be retained during postback. The page framework uses view state to persist control settings between postbacks.

You can use view state in your own applications to do the following:

Keep values between postbacks without storing them in session state or in a user profile.

Store the values of page or control properties that you define.

Create a custom view state provider that lets you store view state information in a SQL Server database or in another data store.

For example, you can store information in view state that your code can access during the page load event the next time that the page is sent to the server.

Amit Shah

Author: murali04 Jan 2011 Member Level: Bronze   Points : 1

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.

Author: sugandha25 Jan 2011 Member Level: Gold   Points : 1

HTML is a stateless protocol. even web server does not maintain the state of the page. every time when the page is posted, information is sent to server, event handling takes place and page is sent back to client browser. This leads to information loss. Viewstate helps to overcome this. Whenever is page is rendered back asp.net check web controls has any changes if so it collects all the information and adds in "form" tag. when the page is posted controls are updated accordingly.

It uses hidden field names_VIEWSTATE to store the information and add to "form" tag

Author: Mukta Aggarwal06 Apr 2011 Member Level: Silver   Points : 1

Viewstate can be store on server side by calling
protected override void SavePageStateToPersistenceMedium(object state)
protected override object LoadPageStateFromPersistenceMedium()
both methods. which is inbuild functions

Author: jeet singh bhandari08 Apr 2011 Member Level: Silver   Points : 1

ViewState stores the objects serializable in a hidden field
on the page.
ViewState is used to retain the state of server-side
objects between postbacks.
Viewstate is transported between client and the server.

Author: Prasad kulkarni09 Apr 2011 Member Level: Gold   Points : 0

Good information by you all

Thanks for sharing

Author: rameSH sinGH22 Apr 2011 Member Level: Silver   Points : 1

View State The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested for the first time versus when the form is posted (sent to the server), which allows you to program accordingly.

Author: Kuldeep Kumar25 Jun 2011 Member Level: Bronze   Points : 1

ASP.NET server-side controls include a facility for holding on to a page's visual state—it's a property in
the Page named ViewState , and you can easily access it any time you need. ViewState is a dictionary (a
name-value collection) that stores any serializable object.

Most ASP.NET server-side controls manage their visual state by storing and retrieving items in the
ViewState . For example, a selection control might maintain the index of the selected item between posts
so that the control knows which item gets the "selected" tag.

The entire state of a page is encoded in a hidden field between posts. For example, if you browse to an
ASPX page and view the source code coming from the server, you'll see the ViewState come through as
a BASE 64–encoded byte stream.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: