All About View State - State Management


All About View State - State Management

ASP.NET State Management Overview

What is View State?

View State is one of the most important and useful client side state management mechanism. It can store the page value at the time of post back (Sending and Receiving information from Server) of your page.

ASP.NET pages provide the ViewState property as a built-in structure for automatically storing values between multiple requests for the same page.

  • If you want to add one variable in View State,

  • For Retrieving information from View State
 string Test=ViewState["TestVal"];

Advantages of ViewState

  • It's easy to implement
  • No server resources are required
  • To enhanced security features ,like it can be encoded and compressed. 

Disadvantages of ViewState

  • It can be performance overhead if we sote a larger amount of data.
  • Stored in a hidden filed in hashed format still it can be easily trapped.
  • It does not have any support on mobile devices.

 Where is view state stored?

  • View State use Hidden field to store its information in a encoding format.

For Example:
ViewState["Value"] = TextBox1.Text;

Now, Run you application, In Browser, RighClick > View Source , You will get the following section of code

Enabling and Disabling View State
You can enable and disable View state for a single control as well as at page level also. To turnoff view state for a single control , set EnableViewState Property of that control to false. e.g.: TextBox1.EnableViewState =false;

To turnoff the view state of entire page, we need to set EnableViewState to false of Page Directive as shown bellow.


Even you disable view state for the entire page , you will see the hidden view state tag with a small amount of information, ASP.NET always store the controls hierarchy for the page at minimum , even if view state is disabled.

For enabling the same, you have to use the same property just set them as True

as for example, for a single control we can enabled view state in following way, 

TextBox1.EnableViewState =true;

All About View State - State Management Reviewed by Ravi Kumar on 10:10 AM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form


Email *

Message *

Powered by Blogger.