State Management Technique In .NET : A short Trip


This article gives you a short idea about a State Management Technique in .NET. You will know What is State Management? Why we use State Management? Types of State Management etc.

State Management Technique in .NET: A short Trip


What is State Management ?
It is the Technique by which we can maintain the sate and Information of the page over multiple request.

Why we use State Management?


Page information is not persist beyond each life cycle of page because pages are destroyed and recreated each time of round trip to server
We can call this round trip as POSTBACK
ASP.NET provide a verious ways of maintaining state of page

What are the types of State Management?


There exist two types of State Management
1. Client Side State Management - store values on Client
2. Server Side State Management - store values on Server

Which is good to use State Management?


This is the critical question, it is typically depend on following things
1. How long do you want to store the information
2. How information do you need to store
3. What are your browser capabilities

Client Side State Management?


Client side State Management handle with the following ways
- View state
- Control state
- Hidden fields
- Cookies
- Query strings

basically when we want a minimal security and fast performance then client side State Management is good option

View State


view state is use to store our own page-specific values across round trips. Every ASP.NET page has a property of View state to store values between round trips
We can Turnoff viewstate for specific page. it has some bold features like

- server resources not required.
- ease in implementation.
- Fast in Performance.

When to use State Management:

It is used when we need to store small amounts of information for a page

Control State
This is not much popular way to persist state. it persist custom control data between multiple postbacks. Like View state we can not
SWITCH OFF control state. It is good way to managing state of control
Let's see some bold features
- a more reliable method for managing the state of controls
- Versatile
when to use : It is used when we need to store small amounts of for a control between round trips

Hidden Fields
Hidden fields maintain the state between postabacks. we can store user specific data in hidden fields. we can used to when security is not an issue
It has some disAdvantages like it has storage limitation, it will slow down perfomance if we trying to put large value in it, Potential security risks.

some of the bold features are
- widely used
- Support to almost all browsers.
- simple architecture.

when to use : It is used when we need to store small amounts of frequently changed data

Cookies
Basically cookies are small files that are stored on client machine. We can create cookies. There are two types of cookies exist
1. Persistent cookie
2. Non Persistent cookie

where Persistent cookie has expiration period
when to use : It is used when we need to store small amounts of data where security is not aspect

Query Strings
A Querystring is the data that is appended to the URL with the '?' sign, however it is simple but limited way of transfering data

Query Strings has advantages and drawbacks too

Query Strings good points are as follows
- easy to build
- support from all Browsers

Query Strings Drawbacks
- URL is visible to user leads to risk of data loss
- URL length limitation
when to use : It is used when we need to Transfer small amount of data like username

--------------------------------------------------

Server Side State Management ?

In Server Side State Management information stored on server so it has a higher security than client side.
Server side State Management handle with the following ways
- Application state
- Session state
- Profile properties

Application state
It is good way to accessible information through all application which is managed by server. We can store our application level values in this veriables.
It get's initialised in GLOBAL.ASAX. This is common for all users.

some of the bold features are as follows
- Easy to implement
- Lock / Unlocking facility avaliable
- Information accessible through all pages
- Information accessible to all users

when to use : It is used when we need to store global information that is not chnaged frequently but used by many users

Session state
This is a good way to store user specific information, It allows you to store and retrive values for a specific user between
multiple postbacks. You do not have to declear session veriable explicitly.

Some Advantages are as follows
- support to large dataTypes
- User wise information can be maintain
This is short lesson about the CSS.
when to use : It is used when we need to store short-lived information that is specific to an individual user

Profile properties
It is not very well known way to maintaining data accross postbacks
This allow you to store user specific data, it is same like session but Profile data not get lost even after session expires
Profile properties are stored in persistent format

when to use : It is used when we need to store user-specific information that needs to be persisted after the user session is expired

Thanks
There are many ways to transfer data from one page to another.Many of new Web application developers May get confused about it. This is short attempt to make the confusion clear.
Suggestion are most welcome

Thanks
koolprasad2003


Comments

Author: niraj kumar mundel07 Jan 2012 Member Level: Silver   Points : 0

yes this is a good article for the user of asp .net


use this article to read about state view in asp .net


regards

Niraj Kumar Mundel

Author: venkataramaiah24 Feb 2012 Member Level: Bronze   Points : 0

so nice article..........


it giving total basic information about the state management

Guest Author: 31 May 2012

good information .... thanks for uploading info ....

Guest Author: vaibhav13 Dec 2012

where view state is stored ?

Author: Ranajoy11 Aug 2013 Member Level: Silver   Points : 2

Most informative article which helps a lot for the developers at beginner's level.It's generally cover-up the basic knowledge of the State Management. All the points clearly written with their advantages and disadvantages which is quite helpful to gather knowledge on this.

Author: Arun Kambhammettu14 Aug 2013 Member Level: Gold   Points : 5


This is very informative, but you can add cons of state Management also then it will be in good shape.

I am adding few points for issues encountered in using application management.

-->The memory occupied by variables stored in an application state is not released until the value is either removed or replaced.This is an overhead on the Web server and the server response will be slow.
-->Multiple pages within an application can access values stored in an application state simultaneously. It requires explicit synchronization methods to avoid deadlocks and access violations.

As s best practise,
Don't use cookies,query strings and hidden controls to store security-sensitive information. This is because information can be easily read or manipulated.

Author: ketan Italiya26 Aug 2013 Member Level: Gold   Points : 6

Client side State management Options:

ASP.NET provides various client side state management options like Cookies, QueryStrings (URL), Hidden fields, View State and Control state (ASP.NET 2.0). Let's discuss each of client side state management options.

Bandwidth should be considered while implementing client side state management options because they involve in each round trip to server. Example: Cookies are exchanged between client and server for each page request.
Cookie:

A cookie is a small piece of text stored on user's computer. Usually, information is stored as name-value pairs. Cookies are used by websites to keep track of visitors. Every time a user visits a website, cookies are retrieved from user machine and help identify the user.

Advantages:

Simplicity

Disadvantages:

Cookies can be disabled on user browsers
Cookies are transmitted for each HTTP request/response causing overhead on bandwidth
Inappropriate for sensitive data



ASP.Net State Management Techniques
By Member 2356127, 17 Jan 2007
1.58 (8 votes)

Introduction
This article discusses various options for state management for web applications developed using ASP.NET. Generally, web applications are based on stateless HTTP protocol which does not retain any information about user requests. In typical client and server communication using HTTP protocol, page is created each time the page is requested.

Developer is forced to implement various state management techniques when developing applications which provide customized content and which "remembers" the user.

Here we are here with various options for ASP.NET developer to implement state management techniques in their applications. Broadly, we can classify state management techniques as client side state management or server side state management. Each technique has its own pros and cons. Let's start with exploring client side state management options.
Client side State management Options:

ASP.NET provides various client side state management options like Cookies, QueryStrings (URL), Hidden fields, View State and Control state (ASP.NET 2.0). Let's discuss each of client side state management options.

Bandwidth should be considered while implementing client side state management options because they involve in each roundtrip to server. Example: Cookies are exchanged between client and server for each page request.
Cookie:

A cookie is a small piece of text stored on user's computer. Usually, information is stored as name-value pairs. Cookies are used by websites to keep track of visitors. Every time a user visits a website, cookies are retrieved from user machine and help identify the user.

Let's see an example which makes use of cookies to customize web page.
Collapse | Copy Code

if (Request.Cookies["UserId"] != null)
lbMessage.text = "Dear" + Request.Cookies["UserId"].Value +
", Welcome to our website!";
else
lbMessage.text = "Guest,welcome to our website!";
//If you want to store client's information use the below code
Response.Cookies["UserId"].Value=username;

Advantages:

Simplicity

Disadvantages:

Cookies can be disabled on user browsers
Cookies are transmitted for each HTTP request/response causing overhead on bandwidth
Inappropriate for sensitive data

Hidden fields:

Hidden fields are used to store data at the page level. As its name says, these fields are not rendered by the browser. It's just like a standard control for which you can set its properties. Whenever a page is submitted to server, hidden fields values are also posted to server along with other controls on the page. Now that all the asp.net web controls have built in state management in the form of view state and new feature in asp.net 2.0 control state, hidden fields functionality seems to be redundant. We can still use it to store insignificant data. We can use hidden fields in ASP.NET pages using following syntax

protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1;

//to assign a value to Hidden field

Hidden1.Value="Create hidden fields";

//to retrieve a value

string str=Hidden1.Value;

Advantages:

Simple to implement for a page specific data
Can store small amount of data so they take less size.

Disadvantages:

Hidden field values can be intercepted(clearly visible) when passed over a network

View State:

View State can be used to store state information for a single user. View State is a built in feature in web controls to persist data between page post backs. You can set View State on/off for each control using EnableViewState property. By default, EnableViewState property will be set to true. View state mechanism poses performance overhead. View state information of all the controls on the page will be submitted to server on each post back. To reduce performance penalty, disable View State for all the controls for which you don't need state. (Data grid usually doesn't need to maintain state). You can also disable View State for the entire page by adding EnableViewState=false to @page directive. View state data is encoded as binary Base64 - encoded which add approximately 30% overhead. Care must be taken to ensure view state for a page is smaller in size.


Advantages:

Simple for page level data
Encrypted
Can be set at the control level

Disadvantages:

Makes a page heavy

Query strings:

Query strings are usually used to send information from one page to another page. They are passed along with URL in clear text. Now that cross page posting feature is back in asp.net 2.0, Query strings seem to be redundant. Most browsers impose a limit of 255 characters on URL length. We can only pass smaller amounts of data using query strings. Since Query strings are sent in clear text, we can also encrypt query values. Also, keep in mind that characters that are not valid in a URL must be encoded using Server.UrlEncode.

Let's assume that we have a Data Grid with a list of products, and a hyperlink in the grid that goes to a product detail page, it would be an ideal use of the Query String to include the product ID in the Query String of the link to the product details page (for example, productdetails.aspx?productid=4).


Advantages:

Simple to Implement

Disadvantages:

Human Readable
Client browser limit on URL length
Cross paging functionality makes it redundant
Easily modified by end user

Control State:

Control State is new mechanism in ASP.NET 2.0 which addresses some of the shortcomings of View State. Control state can be used to store critical, private information across post backs. Control state is another type of state container reserved for controls to maintain their core behavioral functionality whereas View State only contains state to maintain control's contents (UI). Control State shares same memory data structures with View State. Control State can be propagated even though the View State for the control is disabled. For example, new control Grid View in ASP.NET 2.0 makes effective use of control state to maintain the state needed for its core behavior across post backs. Grid View is in no way affected when we disable View State for the Grid View or entire page
Server Side State management:

As name implies, state information will be maintained on the server. Application, Session, Cache and Database are different mechanisms for storing state on the server.

Care must be taken to conserve server resources. For a high traffic web site with large number of concurrent users, usageof sessions object for state management can create load on server causing performance degradation
Application object:

Application object is used to store data which is visible across entire application and shared across multiple user sessions. Data which needs to be persisted for entire life of application should be stored in application object.

In classic ASP, application object is used to store connection strings. It's a great place to store data which changes infrequently. We should write to application variable only in application_Onstart event (global.asax) or application

Author: Umesh Bhosale26 Mar 2014 Member Level: Silver   Points : 0

Nice Article



  • 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:
    Email: