As we know, websites and web applications are based on HTTP protocol and they are stateless, which means they don’t know whether the requests are all from the same client. Pages are destroyed and recreated with each round trip to the server, and therefore information will be lost on each round trips, which is a major issue in developing websites and web applications.

But State Management is not a very big pain when developing websites and web applications using ASP.Net. ASP.Net framework provides number of techniques for State Management both server-side and client-side.

Application state, Session state, and Profile properties are the example of server-side state management techniques, whereas ViewState, Cookies, Hidden Fields, and Query Strings are the example of client-side state management techniques.

Server-side State Management techniques in ASP.Net:

1) Application State:

ASP.Net allows you to save values using application state — which is an instance of the HttpApplicationState class — for each active Web application. Application state is a global storage mechanism that is accessible from all pages in the Web application, regardless of which user requests a page. Thus, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages across all users.

Application state is stored in a key/value dictionary that is created during each request to a specific URL. You can add your application-specific information to this structure to store it between page requests. Once you add your application-specific information to application state, the server manages it.

2) Session State:

ASP.Net allows you to save values by using session state — which is an instance of the HttpSessionState class — for each active Web-application session.

Session state is similar to application state, except that it is scoped to the current browser session. If different users are using your application, each user session will have a different session state. In addition, if a user leaves your application and then returns later, the second user session will have a different session state from the first.

Session state is structured as a key/value dictionary for storing session-specific information that needs to be maintained between server round trips and between requests for pages.

3) Profile Properties:

ASP.Net provides a feature called profile properties, which allows you to store user-specific data. This feature is similar to session state, except that the profile data is not lost when a user's session expires. The profile-properties feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user. The ASP.NET profile allows you to easily manage user information without requiring you to create and maintain your own database.

To use profile properties, you must configure a profile provider. ASP.NET includes a SqlProfileProviderclass that allows you to store profile data in a SQL database, but you can also create your own profile provider class that stores profile data in a custom format and to a custom storage mechanism such as an XML file, or even to a web service.

Client-side State Management techniques in ASP.Net:

1) ViewState:

Each control on a ASP.Net Web Forms page, including the page itself, has a ViewState property, it is a built-in struture for automatic retention of page and control state, which means you don’t need to do anything about getting back the data of controls after posting page to the server. When the page is posted, one of the first tasks performed by page processing is to restore view state. You can add custom values to the ViewState as well.

2) Cookies:

A cookie is a small amount of data stored either in a text file on the client’s file system or in-memory in the client browser session. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

3) Hidden Fields:

ASP.Net allows you to store information in a HiddenField control, which renders as a standard HTML hidden field. A hidden field does not render visibly in the browser and the data is available only when the form is processed. You can set its properties just as you can with a standard control. A hidden field acts as a repository for any page-specific information that you want to store directly in the page.

4) QueryStrings:

Query strings provide a simple but limited way of maintaining some state information.You can easily pass information from one page to another, But most browsers and client devices impose a 255-character limit on the length of the URL. In addition, the query values are exposed to the Internet via the URL so in some cases security may be an issue.