Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
1.1k views
in Blog Post by 20 34 41
edited by

With each request for a page from the server, a new instance of the Web page class is produced. This would generally indicate that with every new request, all of the data on the page would be lost.

In ASP.NET Web Forms, have several state management to preserve the value of a variable between multiple requests to the Web server. 

This post will go through some of the state management, which includes the following:

  1. View State 
  2. Session State 
  3. Application State


1) View State 

This state enables you to save a small part of data for your public variable, which can then be retrieved in multiple functions on the same page.

Public int count {

get { return (int)ViewState["count"]; }

set { ViewState["count"] = value; }

} 


2) Session State 

This state enables you to save public variable data, which can then be accessed across multiple different pages or requests for the same user.

//set

Session["count"] = 1;

//get

int value = (int)Session["count"];

 

3) Application State 

This state allows you to save public variable data that will be available to all users and sessions of your application.it is an ideal place to store application configuration properties or shared data. 

//set

Application["count"] = 1;

//get

(int)Application ["count"];

If you don’t ask, the answer is always NO!
...