Types of state management
There are two types of state management techniques:
A. client side
B. server side.
Client side state management are as below:
- Hidden Field
- View State
- Cookies
- Control State
- Query Strings
Server side state management are as below
- Session
- Application
Lets see all some of the state with example:
Hidden Field
<asp:HiddenField ID="HiddenField1" runat="server" />
if (HiddenField1.Value != null)
{
int val= Convert.ToInt32(HiddenField1.Value) + 1;
HiddenField1.Value = val.ToString();
Label1.Text = val.ToString();
}
ViewState
protected void PageLoad(object sender, EventArgs e)
{
if (IsPostBack)
{
if (ViewState["count"] != null)
{
int ViewstateVal = Convert.ToInt32(ViewState["count"]) + 1;
Label1.Text = ViewstateVal.ToString();
ViewState["count"]=ViewstateVal.ToString();
}
else
{
ViewState["count"] = "1";
}
}
}
protected void Button1Click(object sender, EventArgs e)
{
Label1.Text=ViewState["count"].ToString();
}
Session
Session["Count"] = 0;
Application
Application["Count"] = Convert.ToInt32(Application["Count"]) + 1; //Set Value to The Application Object
Label1.Text = Application["Count"].ToString(); //Get Value from the Application Object
0 Comment(s)