State Management in ASP.NET

Lets we talk about State Management and take overview of it. It is the common topic in all the technology such as .NET , PHP ,JAVA. It plays an very important role in web technologies.Have you ever check whenever you fill any form and after submit the form all the Textbox or any other control are becomes Empty. WHY? So State Management provide us the Solution regarding the Solution.

State Management

1. All the pages are Stateless.
Example : Whenever user fill the details in the form (eg Name ,Email ,Address) and press submit button then request goes to server and new page is introduce with all the empty fields on client Machine. All the controls are empty shows pages are stateless.To Save these details we use State Managements Technique.

There is an sample of form when I fill the data in the field and press submit button after submit the form on server new page is formed on the client machine and all the field are empty it prove that all the pages are Stateless.

State Management

Empty Form

Types of State Management
There are two type of State Management:
1. Client Side State Management.
2. Server Side State Management.

Client Side State Management
1. To use the client resources. ( Means to Store the information in Client's Harddisk or Memory )
2. Not Secure. ( Important information regarding credential or password is not secure in Client Side Management)
3. Faster as Compare to Server-Side State Management.

Now let we Discuss about the type of

Client Side State Management

1. Cookies
2. Query String
3 Hidden
4. View State
5. Control State ( Add in 2.0 .NET)

Cookies and Query String are common in .NET, PHP, JAVA.

Hidden and View State are used only in .NET.

Server-Side State Management
1. Server-Side State Management means to use the server side resource.
2. Information is secure.
3. It is slow as compare to Client-Side State Management.

Types of Server-Side State Management
1. Application
2. Session
3. Profile (Add in 2.0 .NET)
4. Cache Memory

Now let us these Terms in Briefly


Q. Where Cookies Data Store?
Q. Which we Store in it? (String , Int etc)
Q. What is the Scope of Cookies? (Single Page , Multiple Page etc)

Let us discuss the answer of above questions
1. Data Store in the Text-File and these Text-File are made on the Client-Side.
2. We can store String values not object.
3. Scope is multiple page or on Current Machine.
4. By-default Cookies are Temporary and these Cookies ( Temporary) Store in Browser. ( Browser Close Cookies Destroy)
5. But we can Create Permanent Cookies. In Permanent Cookies we can specify the expiry day,time etc.
6. Cookies are URL specific.
7. Initial Size of Cookies are 50 bytes.
8. Maximum Size of the Cookies are 4096 bytes or 4 KB.
9. Per Website Maximun Number of Cookies is 20.
10. On Every request Cookies goes to the server and server expire the Cookies.

Drawback of Cookies
1. Size of Cookies are Limited.
2. User can easily manipulate the Cookies.
3. User can Enable and Disable the Cookies.

Query String

1. In Query String Data Concatenate in URL.

In the Above url PostResource.aspx is the page name.
? define the Query String
ResourceId define the Query string variable Name throug which we can pass the data from one page to another.

2. We can Store Sting Value not object.

3.Scope of the Query String is Next Page Only.
4. Maximum Size of the URL is 2086 Character and it is varies from browse to browser.

Drawback of Query String
1. Size Limitation.
2. Not Secure. All the information is display in the URL.

View State (it is the concept of .Net only)

1. Information store in the form of #key,Compressed and encoded form.
2. In view state we can store string value as well as object.
3. We can store any serializable-object.
4. Scope of View State is Current Page only.
5. We can also specify encription mode for view-state.

Drawback of View State
1. Performance of the page is Slow in case of Large Volume of data.

Hidden Controls

1. It is Similar to Query String.
2. In Hidden Control we can store String values not object.
3. Scope of the hidden is Next Page only.

Now some question arise in our mind then what is the Difference between Query String and Hidden.
1. Generally Query String data is display in the web address. But for security reasons we use Hidden Controls instead of Query String because it's data or information is not display in the Address Bar.
2. But Performance wise query string is best as compare to Hidden Control.

This is enough for the Client Side State Management. In the Next Article we will discuss about the Server Side State Management and later on we will do some practical for deep and better understanding the concept of State Management.

Feel Free to post the comment. So that I will try to improve the quality of the content.


Author: Sridhar Thota19 May 2015 Member Level: Gold   Points : 8

server side state management:
Application state:
1.The application state is maintained in the application level. It is common for all users in a application.
2.Application variable can be set as
Application[ "Countvariable" ] = Convert.ToInt
32(Application[ "Countvariable" ]) + 1;
lbl.text= Application[ "Countvariable" ].ToString();
3.Some application events in global.asax are
void Application_Start( object sender, EventArgs e)
Application[ "Countvariable" ] = 0;

Session state:
1.Session state is maintained user level. It is different for different users.
2.Session variable can be set as
Session[ "Countvariable" ] = Convert.ToInt32(Session["Countvariable" ]) + 1;
3.Some session events in global.asax are
void Session_Start( object sender, EventArgs e)
Session[ "Count" ] = 0;
There are different session modes
1.Inproc Session:
Session maintained in the website process is called Inproc Session.
Restarting website will erase the session.

2.State server session:
Session maintained out side the website in the state server is called state server session.
Restarting state server will erase the session.

3.Sql server session:
Session maintained out side the website in the Sql server database is called sql server session.
Session is maintained until we delete from the database table.


DNS Member.
"Hope for the best.. prepare for the worst.."

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: