How ASP.net maintain state for its controls..?


In this article I'm trying to explain how asp.net maintain state for it's controls. Client make a request server respond based on client request i the mean time controls maintain state or not. If it's maintain the state what happen inside to maintain the state. If it's not maintain the state what is the problem.

How ASP.net maintain state for its controls:



• Client makes a request for page
• Server process the page and concatenates all the result into a string.
• This string is converted into base64 encoding format. Which is not encrypted and secured format.
• This data is now stored in hidden field. Which is created by (1 or more) asp.net implicitly.
• Now, the page is returned to client along with user created control and also hidden fields.

state

• Now, client modify & resubmits the page to server.
• Server first off all now reads the hidden field data so that it retains its previously given result. Then starts processing the page where old results and new values.
• It repeats this cycle for every client as long as client is working with current page.
• This result in state full behavior of page related to controls.

state1

Source Code:




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="State.aspx.cs" Inherits="State" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

TextBox:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
HTML TextBox :
<input id="Text1" type="text" />
<br />

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</div>
</form>
</body>
</html>


Code Behind:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class State : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "after click a button data will not store in DataSource";
}
}


OutPut:



output

OutPut1


Article by naveensanagasetti
I hope you enjoyed to read my article, If you have any queries out of this then please post your comments.

Follow naveensanagasetti or read 139 articles authored by naveensanagasetti

Comments

No responses found. Be the first to comment...


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