State management In ASP.Net.

1.      State management is the process by which you maintain state and page information over multiple requests for the same or different pages.
– ASP.NET offers a number of places to store state, both on the client and server.
          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.
1. View state
– The ViewState property  object for retaining values between multiple requests for the same page

– ViewState[“Name”]=”Value”;

String sString;
sString = Server.UrlEncode(“string in InitialPage.aspx”);
Response.Redirect(“Page.aspx?Value=” & sString);

String sString;
sString = Request.QueryString(“Value”);
Response.Write(“Your name is ” & sString);

HttpCookie StudentCookies = new HttpCookie(“StudentCookies);

Get Cookies Value

    4. 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.

     Server – Side State Management

    1. Session
In this option session state used to store session specific information for a
    Web site. In session state, the scope fo session state is limited to the
    current browser session. In case, many users are accessing the same Web
    application, each will have a different session state. If a user exits from a
    Web applicatin and returns later, it will be a different session state.

  InitialPage.aspx stores value in session before sending it

Session[“MyName”] = “MeeraAcademy”;

‘DestinationPage.aspx retrieves the value from InitialPage.aspx’s session

String sString;
sString = Session[“MyName”].ToString();
Response.Write(“Your Name is : ” & sString);

Application State:
ASP.Net provides application state as a means of storing global application specific information. The information in the application state is stored in a key value pair and is used to maintain data consistency between server round trips and between pages..
– Application objects are application level global variables, that need to be shared for all user sessions. Thus, data specific to a user should’nt be saved in application objects. While using application objects, the objects are locked so that multiple page requests cannot access a specific application object.

Application[“MyData”] = “MeeraAcademy”;

DestinationPage.aspx gets the value from the Application State

String sString = Application[“MyData”].ToString();

(Visited 1 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha *