April 08, 2011

What is View State and its Advantages and Disadvantages?

 Definition:
           View State is the technique used by ASP.NET web pages to keep the state of the page across post backs. It stores data in a hidden field named __VIEWSTATE inside the page in Base-64 encoded formats. The encoding and decoding of the view state data is done by the LosFormatter class. 


There is a provision of turning off ViewState at control level and also at page level using the property EnableViewState.


Advantages:
    1. It does not require any server resource.
    2. Automatically retains the state of the page, which removes the headache of the     developer to maintain it manually.
    3.Provide the flexibility of enabling and disabling at control and page level. Also provide control to check and validate whether the view state data is tampered or not (when you set the EnableViewStateMac to true ASP.NET runs a message authentication check(mac) on the viewstate data to check whether the data is modified on the client end).


Disadvantages:
    1. Since the view state data is stored inside the page it increases network overhead as all the data travel along with the page.
    2. As data is stored in encoded format, it can be easily decoded. so it is advised not to store sensitive data in view state.


to be continue..

No comments:

Post a Comment

Your comments are valuable.