ASP.net 2.0 page State continuation program

Source: Internet
Author: User
Tags sessions

Developers of ASP.net controls use ViewState and control state to maintain state information between requests made by the browser. Typically, this information is passed to the client as a hidden field in the HTML markup that is rendered by the page. The page status is then passed back to the server and restored to the control or page as part of the next form submission. Even if the browser uses the HTTP protocol, which is defined as stateless, the developer of the control can easily provide a richer application experience with the ability to temporarily store state information.

ASP.net 2.0 allows you to modify the position and manner of temporarily maintaining page status. In some cases, it may be preferable to avoid sending data back and forth between the client and the server. ASP.net 2.0 provides two page state continuation programs that are hiddenfieldpagestate continuous (we've mentioned) and SessionPageStatePersister. SessionPageStatePersister uses server sessions related to browser sessions to store data. The use of SessionPageStatePersister has positive and negative two aspects. For pages sent to (from) browsers, the use of sessions (rather than hidden fields) avoids an increase in size. In many cases, the page state is an important part of all markup. However, storing data in a session consumes valuable server resources. In addition, the hidden field does not have a related timeout like a session. You can configure an application to hold the session to a back-end database and avoid adding the load directly to the WEB server. This will also extend to Web farm scenarios.

To use an ongoing program other than the default persistence program, you need to override the page's PageStatePersister property and return an instance of another persistent program. First, the following simple page populates a ArrayList with only a large number of digits, and then binds it to a GridView control.

The following is a reference fragment:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "
<script runat=" Server "
protected override PageStatePersister PageStatePersister {

get {

return new SessionPageStatePersister (this);

}
}
protected override void OnLoad (EventArgs e) {

base. OnLoad (e);

if (! IsPostBack) {

ArrayList list = new ArrayList ();

for (int i = 0; i < 1000; i++)

{

list. ADD (Convert.ToString (i));

}

Gridview1.datasource = list;

Gridview1.databind ();

}
}
</script>
<title>untitled page</title>
<body>
<form id= " Form1 "runat=" Server "
<div>
<asp:gridview id=" GridView1 "runat=" Server "/>
Asp:button id= "Button1" runat= "Server" text= "Submit"/></DIV>
</form>
</body>
</ Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.