What is state management in ASP.NET.
What is state management in ASP.NET.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brajesh KumarPosted Mar 1, 2017, 7:36 AM
The HTTP protocol is the fundamental protocol of the World Wide Web. HTTP is a stateless protocol means every request is from new user with respect to web server. HTTP protocol does not provide you with any method of determining whether any two requests are made by the same person.
Maintaining state is important in any web application. There are two types of state management system in ASP.NET.
- Client-side state management
- Server-side state management
Client side state management system.
ASP.NET provides several techniques for storing state information on the client. These include the following:view state: ASP.NET uses view state to track values in controls between page requests. It works within the page only. You cannot use view state value in next page.
control state: You can persist information about a control that is not part of the view state. If view state is disabled for a control or the page, the control state will still work.
hidden fields: It stores data without displaying that control and data to the user’s browser. This data is presented back to the server and is available when the form is processed. Hidden fields data is available within the page only (page-scoped data).
Cookies: Cookies are small piece of information that server creates on the browser. Cookies store a value in the user’s browser that the browser sends with every page request to the web server.
Query strings: In query strings, values are stored at the end of the URL. These values are visible to the user through his or her browser’s address bar. Query strings are not secure. You should not send secret information through the query string.
Server side state management system.
The following objects are used to store the information on the server:Application State:
This object stores the data that is accessible to all pages in a given Web application. The Application object contains global variables for your ASP.NET application.
Cache Object:
Caching is the process of storing data that is used frequently by the user. Caching increases your application’s performance, scalability, and availability. You can catch the data on the server or client.
Session State:
Session object stores user-specific data between individual requests. This object is same as application object but it stores the data about particular user.
Brajesh KumarPosted Mar 1, 2017, 1:40 PM
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (ViewState["count"] != null)
{
int ViewstateVal = Convert.ToInt32(ViewState["count"]) + 1;
View.Text = ViewstateVal.ToString();
ViewState["count"]=ViewstateVal.ToString();
}
else
{
ViewState["count"] = "1";
}
}
}
// Click Event
protected void Submit(object sender, EventArgs e)
{
View.Text=ViewState["count"].ToString();
}
Girjesh KumarPosted Mar 1, 2017, 1:38 PM