State Management Types
State Management Types
In ASP.NET there are the following 2 State Management methodologies:
Client-Side State Management
Client-Side State Management, the state related information will get stored on
the client machine
Server-Side State Management
Server Side State Management, the state related information will get stored on
the Server machine
The structure is something like the following,
State Management Scenario
It will be a little difficult to directly evaluate what will be better for our
application. We cannot directly say that we will use client-side or server-side
architecture of State Management.
State Management Techniques
State Management techniques are based on client side and server side. Their
functionality differs depending on the change in state, so here is the hierarchy:
Client-side | Techniques
Client-Side State Management techniques are,
View State
Hidden field
Cookies
Query Strings
Server-side | Technique
Server-Side State Management techniques are,
Session State
Application State
Now I am defining each and every technique in detail with their reference
example.
View State
In general we can say it is used for storing user data in ASP.NET, sometimes in
ASP.NET applications the user wants to maintain or store their data temporarily
after a post-back.. In this case VIEW STATE is the most used and preferred way of
doing that.
This property is enabled by default but we can make changes depending on our
functionality, what we need to do is just change the EnableViewState value to
either TRUE for enabling it or FALSE for the opposite operation.
Points to Remember
Some of the features of view state are:
Hidden Field
A hidden field is used for storing small amounts of data on the client side. In
most simple words it's just a container of some objects but their result is not
rendered on our web browser. It is invisible in the browser.
It stores a value for the single variable and it is the preferable way when a
variable's value is changed frequently but we don't need to keep track of that
every time in our application or web program.
Figure: [Hidden Field Management]
1. // Hidden Field
2.
3. int newVal = Convert.ToInt32(HiddenField1.Value) + 1;
4. HiddenField1.Value = newVal.ToString();
5. Label2.Text = HiddenField1.Value;
Points to Remember
Some features of hidden fields are:
Cookies
A set of Cookies is a small text file that is stored in the user's hard drive using the
client's browser. Cookies are just used for the sake of the user's identity
matching as it only stores information such as sessions id's, some frequent
navigation or post-back request objects.
Whenever we get connected to the internet for accessing a specific service, the
cookie file is accessed from our hard drive via our browser for identifying the
user. The cookie access depends upon the life cycle or expiration of that specific
cookie file.
Cookie | Types
Persistent Cookie
Cookies having an expiration date is called a persistent cookie. This type of
cookie reaches their end as their expiration dates comes to an end. In this
cookie we set an expiration date.
1. Response.Cookies["UserName"].Value = "Abhishek";
2. Response.Cookies["UserName"].Expires = DateTime.Now.AddDa
ys(1);
3.
4. HttpCookie aCookie = new HttpCookie("Session");
5. aCookie.Value = DateTime.Now.ToString();
6. aCookie.Expires = DateTime.Now.AddDays(1);
7. Response.Cookies.Add(aCookie);
Non-Persistent Cookie
Non-persistent types of cookies aren't stored in the client's hard drive
permanently. It maintains user information as long as the user access or uses
the services. Its simply the opposite procedure of a persistent cookie.
1. HttpCookie aCookie = new HttpCookie("Session");
2. aCookie.Value = DateTime.Now.ToString();
3. aCookie.Expires = DateTime.Now.AddDays(1);
4. Response.Cookies.Add(aCookie);
Points to Remember
Some features of cookies are:
Control State
Control state is based on the custom control option. For expected results from
CONTROL STATE we need to enable the property of view state. As I already
described you can manually change those settings.
Points to Remember
Some features of query strings are:
Query Strings
Query strings are used for some specific purpose. These in a general case are
used for holding some value from a different page and move these values to the
different page. The information stored in it can be easily navigated to one page
to another or to the same page as well.
Points to Remember
Some of the features are,