State Management in asp.net

State management means to preserve the state of a control, web page, object/data, and user in the application explicitly because all ASP.NET web applications are stateless, i.e., by default, for each page posted to the server, the state of controls is lost. So State Management can be defined as the technique or the way by which we can maintain/store the state of the page or application until the User's Session ends.

State Management Techniques

ASP.NET provides us with 2 ways to manage the state of an application. It is divided into 2 categories

1. Client-Side State Management
2. Server-Side State Management

Client-Side State Management.

It is a way in which the information which is being added by the user or the information about the interaction happened between the user and the server is stored on the client's machine or on the page itself. The server resources (e.g. server's memory) are not at all utilized during the process.

1. Hidden Field
2. View State
3. Cookies
4. Control State
5. Query Strings

Hidden fields:–
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.


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 before rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.

Control State:-
If you create a custom control that requires view state to work properly, you should use a control state to ensure other developers don’t break your control by disabling view state.

Cookies: –
 Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

Query Strings: -
 Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.




Server-Side State Management

ASP.NET provides another way to store the user's specific information or the state of the application on the server machine. It completely makes use of server resources (the server's memory) to store information.

1. Session
2. Application


Application State:-
 Application State information is available to all pages, regardless of which user requests a page.

Session State:–
 Session State information is available to all pages opened by a user during a single visit.