HiddenFieldPageStatePersister 类

定义

在 Web 客户端上以隐藏的 HTML 元素存储 ASP.NET 页面视图状态。Stores ASP.NET page view state on the Web client in a hidden HTML element.

public ref class HiddenFieldPageStatePersister : System::Web::UI::PageStatePersister
public class HiddenFieldPageStatePersister : System.Web.UI.PageStatePersister
type HiddenFieldPageStatePersister = class
    inherit PageStatePersister
Public Class HiddenFieldPageStatePersister
Inherits PageStatePersister
继承
HiddenFieldPageStatePersister

示例

下面的代码示例演示如何ListBox SqlDataSource使用控件将控件绑定到数据库中的数据。The following code example demonstrates how to bind a ListBox control to data in a database with a SqlDataSource control.

<%@ Page language="C#" %>

<!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>
<%@ 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>

查看示例页后, HiddenFieldPageStatePersister类会在名为 "__VIEWSTATE" 的<hidden> 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>  

注解

ASP.NET 页可以将Page状态存储在本质上无状态 HTTP 请求和处理和服务任何网页所需的响应之间。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". 用于存储页及其控件的视图状态的默认机制是在页中包含的一个或<hidden>多个 HTML 字段中, 该字段是从 Web 服务器向客户端提供的。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. Page类可以HiddenFieldPageStatePersister使用类来执行此操作。The Page class can use the HiddenFieldPageStatePersister class to do this work. HiddenFieldPageStatePersisterLoad Page实现类的Save PageStatePersister和方法,<hidden>以便可以将状态存储在 Web 客户端上名为 "__VIEWSTATE" 的 HTML 元素中。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. 当客户端请求来自 Web 服务器 (回发) 的同一页面时, 将<hidden>通过 ASP.NET 分析元素并将其转换为状态信息。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.

如果请求的PageStatePersister PageAdapter Page实例具有关联的类, 它将使用GetStatePersister方法从此适配器检索对象。If the Page instance that is requested has an associated PageAdapter class, it retrieves the PageStatePersister object from this adapter using the GetStatePersister method. 适配器可以重写GetStatePersister方法以PageStatePersister返回按特定客户端支持的某种方式存储页和控件状态的对象。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. 例如, SessionPageStatePersister类将页面和控件的状态存储在 Web 服务器上, 而不是客户端, 以减少必须在内存和带宽有可能受到限制的客户端上发送和存储的信息量。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.

可以<hidden> MaxPageStateFieldLength通过属性或通过配置设置来设置 "_VIEWSTATE" HTML 元素的最大大小。 MaxPageStateFieldLengthThe maximum size of the "_VIEWSTATE" <hidden> HTML element can be set through the MaxPageStateFieldLength property or through the MaxPageStateFieldLength configuration setting. 如果设置了此值, 并且 "_VIEWSTATE" 元素的长度超出了最大长度, 则内容将被划分为多个 "_VIEWSTATE" 元素。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.

构造函数

HiddenFieldPageStatePersister(Page)

初始化 HiddenFieldPageStatePersister 类的新实例。Initializes a new instance of the HiddenFieldPageStatePersister class.

属性

ControlState

获取或设置一个对象,该对象表示当前 Page 对象包含的控件用于跨 Web 服务器的 HTTP 请求保留的数据。Gets or sets an object that represents the data that controls contained by the current Page object use to persist across HTTP requests to the Web server.

(继承自 PageStatePersister)
Page

获取或设置为其创建视图状态持久性机制的 Page 对象。Gets or sets the Page object that the view state persistence mechanism is created for.

(继承自 PageStatePersister)
StateFormatter

获取一个 IStateFormatter 对象,该对象在对 ViewStateControlState 方法的调用期间用于对包含在 Save()Load() 属性中的状态信息进行序列化和反序列化。Gets an IStateFormatter object that is used to serialize and deserialize the state information contained in the ViewState and ControlState properties during calls to the Save() and Load() methods.

(继承自 PageStatePersister)
ViewState

获取或设置一个对象,该对象表示当前 Page 对象包含的控件用于跨 Web 服务器的 HTTP 请求保留的数据。Gets or sets an object that represents the data that controls contained by the current Page object use to persist across HTTP requests to the Web server.

(继承自 PageStatePersister)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Load()

Page 对象初始化其控件层次结构时,反序列化并加载 HttpRequest 对象中的持久化状态信息。Deserializes and loads persisted state information from an HttpRequest object when a Page object initializes its control hierarchy.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Save()

序列化 ViewStateControlState 属性中包含的任何对象状态,并将状态写入响应流中。Serializes any object state contained in the ViewState or ControlState property and writes the state to the response stream.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅