Skip to main content

State Management Technique in .NET

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 .

Comments

Popular posts from this blog

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.

Resolving 'Setup Account Privileges' error while installing SQL Server

A new installation of Microsoft SQL Server 2012 or Microsoft SQL Server 2008 R2 fails You see the following error message when you try to install a new instance of SQL Server 2012 or SQL Server 2008 R2: Rule "Setup account privileges" failed.

Creating Oracle stored Procedures using TOAD for Oracle

In a database management system, a  stored procedure  is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of  stored procedures  can be helpful in controlling  access to data, preserving  data integrity  and  improving  productivity.