Page.RegisterViewStateHandler 方法

定义

如果调用,则保持页视图状态。

public:
 void RegisterViewStateHandler();
public void RegisterViewStateHandler ();
member this.RegisterViewStateHandler : unit -> unit
Public Sub RegisterViewStateHandler ()

示例

// Create a custom HtmlForm server control named MyForm. 
public class MyForm : HtmlForm
{
   // MyForm inherits all the base funcitionality
   // of the HtmlForm control.
   public MyForm():base()
   {
   }
   // Override the OnInit method that MyForm inherited from HtmlForm.
   
   [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
   protected override void OnInit( EventArgs e)
   {
      // Save the view state if there are server controls on
      // a page that calls MyForm.
      Page.RegisterViewStateHandler();
   }
}
' Create a custom HtmlForm server control named MyForm.
Public Class MyForm
   Inherits HtmlForm
   
   ' MyForm inherits all the base funcitionality
   ' of the HtmlForm control.
   Public Sub New()
   End Sub
   
   ' Override the OnInit method that MyForm inherited from HtmlForm.
   <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
   Protected Overrides Sub OnInit(e As EventArgs)
      ' Save the view state if there are server controls on
      ' a page that calls MyForm.
      Page.RegisterViewStateHandler()
   End Sub
End Class

注解

该方法 RegisterViewStateHandler 通过 HtmlForm 服务器控件自动调用。 如果未调用此方法,则不会持久保存页面视图状态。

备注

通常,仅 HtmlForm 页面的服务器控件调用此方法。

适用于

另请参阅