State
management is the process by which you maintain state and page
information over multiple requests for the same or different pages.
Types of State Management
There are 2 types State Management:
1. Client Side State Management
This
stores information on the client's computer by embedding the information
into a Web page, a uniform resource locator(url), or a cookie. The
techniques available to store the state information at the client end
are listed down below:
View State
Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.
Sample Code
//To Save Information in View State
ViewState.Add("Cherukuri", "Venkateswarlu");
//Retrieving View state
Label1.Text = (string)ViewState["Cherukuri"];
Control State
If
you create a custom control that requires view state to work properly,
you should use control state to ensure other developers donĂ¢€™t break
your control by disabling view state.
Hidden fields
Like
view state, hidden fields store data in an HTML form without displaying
it in the user's browser. The data is available only when the form is
processed.
Sample Code
//Declaring a hidden variable
HtmlInputHidden hidCherukuri = null;
//Populating hidden variable
hidCherukuri.Value = "Venkateswarlu";
//Retrieving value stored in hidden field.
Label1.Text = hidCherukuri.Value;