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
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