State Management in ASP. NETAs we know Web pages are based on the HTTP Protocol which is a stateless protocol, means that there is no information about the request, such as where they are coming from i. Since the page is created each time, the page is requested then destroyed. So we can say that the state is not maintained between client requests by default. ASP. NET developers use various available technologies for State Management. We can classify them as client side state management or server side state management. CLIENT SIDE STATE MANAGEMENT View State View. State is an approach to saving data for the user. Because of the stateless nature of web pages, regular page member variables will not maintain their values across postbacks. View. State is the mechanism that allows state values to be preserved across page postbacks and by default, Enable. View. State property will be set to true. In a nutsheell, View. State Stores values per control by key name, like a Hashtable. Tracks changes to a View State values initial state. Serializes and Deserializes saved data into a hidden form field on the client. Automatically restores View State data on postbacks. Sample To Save Information in View State. View. State. Add Nick. Name, Dolly Retrieving View state. String str. Nick. Name View. State Nick. Name Here is a simple example of using the View. State property to carry values between postbacks. Code Example publicint Some. Integer get object o View. StateSome. Integer if o null return into return 0 a default set View. StateSome. Integer value Control State The purpose of the control state repository is to cache data necessary for a control to properly function. Control. State is essentially a private View. State for your control only, and it is not affected when View. State is turned off. SCHNEIDER_ELECTRIC/SE_LOCAL/APS/APS_POWER/FA244559/SessionState.PNG' alt='Asp Net Session State Serialization' title='Asp Net Session State Serialization' />Control. State is used to store small amounts of critical information. Heavy usage of Control. State can impact the performance of application because it involves serialization and deserialization for its functioning. There are two methods you have to implement in your custom control. Load Control State. Save Control State. Code Example publicclass. Control. State. Web. Control Control region Members privatestring str. State. To. Save endregionregion Methods protectedoverridevoid On. InitEvent. Args ePage. Register. Requires. Autocad 2010 Activation Code 32 Bit more. Control. Statethis base. I always use a wrapper class around the ASP. NET session to simplify access to session variables public class MySession private constructor private MySession. This article explains in detail the Session State Management technique and its modes in ASP. Net. ASP. NET developers use various available technologies for State Management. We can classify them as client side state management or server side state management. Learn and Download VB,C,ASP. Net,SQL Server,PHPNuke,Linux turotials and samples. Troubleshoot your day to day programming challenges. Discuss cutting edge technologies. E9vmZ.jpg' alt='Asp Net Session State Serialization' title='Asp Net Session State Serialization' />On. Inite protectedoverrideobject Save. Control. Statereturn str. State. To. Save protectedoverridevoid Load. Control. Stateobject stateif state nullstr. State. To. Save state. To. String endregionHidden Fields A Hidden control is the control which does not render anything on the web page at client browser but can be used to store some information on the web page which can be used on the page. Hidden fields are used to store data at the page level. These fields are not rendered by the browser, rather its just like a standard control for which you can set its properties. If you use hidden fields, it is best to store only small amounts of frequently changed data on the client. Sample Declaring a hidden variableprotected Html. Input. Hidden hid. Nick. Name Populating hidden variablehid. Nick. Name. Value Page No 1 Retrieving value stored in hidden field. Nick. Name. Value Code Example protectedvoid PageLoadobject sender, Event. Args eif Is. Post. BackLabel. 1. Text string. FormatClicked 0 times, Hidden. Field. 1. Value protectedvoid Button. Clickobject sender, Event. Args eHidden. Field. Value Convert. To. Int. 32Hidden. Field. Value 1. To. String Label. Nitzer Ebb Warsaw Ghetto Rare here. Text string. FormatClicked 0 times, Hidden. Field. 1. Value Cookies A cookie is a small amount of data which is either stored at client side in text file or in memory of the client browser session. Cookies are always sent with the request to the web server and information can be retrieved from the cookies at the web server. Every time a user visits a website, cookies are retrieved from the user machine and help identify the user. Cookies are useful for storing small amounts of frequently changed information on the client. The information is sent with the request to the server. Sample Creating a cookiemy. Cookie. Values. Addmuffin, chocolate my. Cookie. Values. Addbabka, cinnamon Adding Cookie to Collection. Response. Cookies. Addmy. Cookie Getting Values stored in a cookie. Response. Writemy. Cookiebabka. To. String Setting cookie pathmy. Cookie. Path forums Setting domain for a cookiemy. Cookie. Domain forums. Deleting a cookiemy. Cookie. Expires Date. Time. Now. Add. Days 1 Code Example Storing value in cookie. Http. Cookie cookie new Http. CookieNick. Name cookie. Value David Request. Cookies. Addcookie Retrieving value in cookieif Request. Cookies. Count 0 Request. CookiesNick. Name nulllbl. Nick. Name. Text Welcome Request. CookiesNick. Name. To. String else lbl. Nick. Name. Text Welcome Guest Query String A Query string is used to pass the values or information form one page to another page. They are passed along with URL in clear text. Query strings provide a simple but limited way of maintaining some state information. When surfing the internet you should have seen weird internet addresses such as http www. Webform. 2. aspxABC last. NameXYZThis HTML address uses a Query. String property to pass values between pages. Syntax Request. Query. Stringvariableindex. Count Code Example using System using System. Web. UI publicpartialclassDefault Pageprotectedvoid PageLoadobject sender, Event. Args estring v Request. Query. Stringparam if v nullResponse. Writeparam is Response. Writev string x Request. Query. Stringid if x nullResponse. Write id detected SERVER SIDE STATE MANAGEMENT Application State Application State is used to store information which is shared among users of the ASP. Net web application. Application state is stored in the memory of the windows process which is processing user requests on the web server. Application state is useful in storing a small amount of often used data. If application state is used for such data instead of frequent trips to the database, then it increases the response timeperformance of the web application. In classic ASP, an application object is used to store connection strings. Its a great place to store data that changes infrequently. Code Example 1 Stroing information in application statelock this ApplicationNick. Name Nipun Retrieving value from application statelock thisstring str ApplicationNick. Name. To. String Code Example 2 protectedvoid PageLoadobject sender, Event. Args e Code that runs on page load ApplicationLogin. ID Nipun ApplicationDomain. Name www. nipun. Session State ASP. NET Session state provides a place to store values that will persist across page requests. Values stored in Session are stored on the server and will remain in memory until they are explicitly removed or until the Session expires. It is defined as the period of time that a unique user interacts with a Web application. Session state is a collection of objects, tied to a session stored on a server. Sample Storing informaton in session state.