STATE MANAGEMENT
What is State Management?
When you create any web application either
in asp,
php
,
jsp
, or asp.net all are HTTP based
means all are use HTTP protocol.
And this protocol is stateless protocol means
server dose not aware of that request are
coming from same client or new client.
So, how do we make web pages in
ASP.Net
which will remember about the user, would
be able to find out between old clients
(requests) and new clients (requests).
Solution of the above problem lies in State
Management.
ASP.Net
technology offers following two
state management techniques.
1)
Client side State Management.
2)
Server side State Management.
What is Client side State
Management?
Client side State Management name shows
that all the process depends upon the clients
web browser means all the process of State
Management will done in Client Side. There
are four ways for client side state
management.
View State / Control State.
Hidden Fields.
Query String.
Cookies.
View State / Control State.
ASP.Net
provides View State/Control State
feature to the web forms. View State is used
to remember controls state when page is
posted back to server.
ASP.Net
stores view
state on client site in hidden field
__
ViewState
in encrypted form.
When page is created on web sever this
hidden control is populate with state of the
controls and when page is posted back to
server this information is retrieved and
assigned to controls. You can look at this field
by looking at the source of the page (
i.e
by
right clicking on page and selecting view
source option.)
<input
type="hidden" name="__VIEWSTATE"
value="dNrATo45Tm5QzQ7Oz8AblWpxPjE9
MMl0Aq765QnCmP2TQ=="
/>
You do not need to worry about this as this is
automatically handled by
ASP.Net
. You can
enable and disable view state behavior of
page and its control by specifying
'
EableViewState
' property to true and false.
You can also store custom information in the
view state as described in following code
sample. This information can be used in
round trips to the web server.
Example:
C#
// This will save above string in
viewstates
ViewState
[“Temp”] = “My Name is
Amit
”;
//Fetching value from view state.
String
Vals
=
ViewState
[“Temp”].
ToString
();
If you take normal html controls and submit
the page than that controls does not have
view state or control state so they loose the
value of controls while in asp.net Microsoft
provide this functionality so after submitting
page if you take all server controls than they
will not leave that data from the textbox or
any other controls.
By default,
ViewState
is enabled for all server
controls.
ViewState
can be enabled and
disabled in any of the following ways.
∙
Page Level
∙
Control Level
∙
Application Level / Machine Level
Page Level:
To enable or disable
ViewState
in the Page
Level, use the following in the Page directive
of the ASP.NET page.
Example:
<%@
Page
EnableViewState
="False" %>
or
<%@
Page
EnableViewState
="True"
%>
Control Level:
To enable or disable
ViewState
at the Control
Level, use the following:
Example:
<
asp:TextBox
id="
txtName
"
runat
="server
”
EnableViewState
="false"
/>
or
<
asp:TextBox
id="
txtCode
"
runat
="server"
EnableViewState
="true"
/>
Application Level:
To enable or disable
ViewState
in the Application Level, use the
following: in
Web.Config
.
Example:
<pages
enableViewState
="false"
/>
or
<pages
enableViewState
="true"
/>
Machine Level:
To enable
ViewState
in the Machine Level,
use the following: in
Web.Config
.
Example:
<pages
enableViewState
="true"
enableViewStateMac
="true"
...
/>
<
machineKey
... validation="3DES" />
or
<pages
enableViewState
="false"
...
/>
Tip: "View State Is Invalid" Error Message When You Use
Server.Transfer
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Comments 0
Log in to post a comment