Export (0) Print
Expand All

HiddenFieldPageStatePersister Class

Stores ASP.NET page view state on the Web client in a hidden HTML element.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

'Declaration
Public Class HiddenFieldPageStatePersister
	Inherits PageStatePersister
'Usage
Dim instance As HiddenFieldPageStatePersister

public class HiddenFieldPageStatePersister extends PageStatePersister
public class HiddenFieldPageStatePersister extends PageStatePersister
Not applicable.

ASP.NET pages can store Page state between the inherently stateless HTTP request and response required to process and serve any Web page. This state is called "view state". The default mechanism used to store view state for a page and its controls is in one or more <hidden> HTML fields included in the page that is served to a client from a Web server. The Page class can use the HiddenFieldPageStatePersister class to do this work. HiddenFieldPageStatePersister implements the Save and Load methods of the PageStatePersister class so that the Page can store state in a <hidden> HTML element named "__VIEWSTATE" on a Web client. When the client requests the same page from the Web server (a postback), the <hidden> element is parsed and converted to state information by ASP.NET.

If the Page instance that is requested has an associated PageAdapter class, it retrieves the PageStatePersister object from this adapter using the GetStatePersister method. Adapters can override the GetStatePersister method to return a PageStatePersister object that stores page and control state in some way that a specific client supports. For example, the SessionPageStatePersister class stores page and controls' state on the Web server, instead of the client, to decrease the amount of information that must be sent and stored on a client that has potentially limited memory and bandwidth.

The maximum size of the "_VIEWSTATE" <hidden> HTML element can be set through the MaxPageStateFieldLength property or through the MaxPageStateFieldLength configuration setting. When this value is set and the length of the "_VIEWSTATE" element would exceed the maximum length, the content is divided into multiple "_VIEWSTATE" elements.

The following code example demonstrates how to bind a ListBox control to data in a database with a SqlDataSource control.

<%@ Page language="VB" %>

<!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>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataReader"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT LastName FROM Employees">
      </asp:SqlDataSource>

      <asp:ListBox
          id="ListBox1"
          runat="server"
          DataTextField="LastName"
          DataSourceID="SqlDataSource1">
      </asp:ListBox>

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

<!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>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataReader"
          ConnectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
          SelectCommand="SELECT LastName FROM Employees">
      </asp:SqlDataSource>

      <asp:ListBox
          id="ListBox1"
          runat="server"
          DataTextField="LastName"
          DataSourceID="SqlDataSource1">
      </asp:ListBox>

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

When the example page is viewed, any view state is stored by the HiddenFieldPageStatePersister class in a <hidden> HTML element named "__VIEWSTATE".

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
  <BODY>
    <form name="_ctl0" method="post" action="sample.aspx" id="_ctl0">
        
      <input type="hidden" name="__VIEWSTATE" value="MgAwADkANgAwADkAOQA3ADgAMQD/AQ8QBQoxMTU2NDc1NjE0EGRkFgICAQ9kFgICAw8PZBAVDQVhc2RhcwhCdWNoYW5hbghDYWxsYWhhbgdEYXZvbGlvCURvZHN3b3J0aAZGdWxsZXIES2luZwhLcmF3YXJpawlMZXZlcmxpbmcETWFyeQdQZWFjb2NrBlN1eWFtYQx0ZXN0IHJlZnJlc2gVDQVhc2RhcwhCdWNoYW5hbghDYWxsYWhhbgdEYXZvbGlvCURvZHN3b3J0aAZGdWxsZXIES2luZwhLcmF3YXJpawlMZXZlcmxpbmcETWFyeQdQZWFjb2NrBlN1eWFtYQx0ZXN0IHJlZnJlc2gUKgMNZ2dnZ2dnZ2dnZ2dnZ2RkZPdhi6U7jBPqVZbj0W8AYFSJ6oiq" />

      <select size="4" name="ListBox1" id="ListBox1">    
        <option value="Buchanan">Buchanan</option>
        <option value="Callahan">Callahan</option>
        <option value="Davolio">Davolio</option>
        <option value="Dodsworth">Dodsworth</option>
        <option value="Fuller">Fuller</option>
        <option value="King">King</option>
        <option value="Leverling">Leverling</option>
        <option value="Suyama">Suyama</option>
      </select>

    </form>
  </BODY>
</HTML>

System.Object
   System.Web.UI.PageStatePersister
    System.Web.UI.HiddenFieldPageStatePersister

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft