Page.RegisterViewStateHandler Page.RegisterViewStateHandler Page.RegisterViewStateHandler Page.RegisterViewStateHandler Method

定義

呼叫時會使網頁檢視狀態被保存 (Persist)。Causes page view state to be persisted, if called.

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 'New
   
   ' 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 'OnInit
End Class 'MyForm

備註

RegisterViewStateHandler方法會自動呼叫透過HtmlForm伺服器控制項。The RegisterViewStateHandler method is automatically called through the HtmlForm server control. 如果這個方法不會叫用,不會保存網頁檢視狀態。If this method is not invoked, the page view state will not be persisted.

注意

一般而言,只有HtmlForm頁面伺服器控制項呼叫這個方法。Typically, only the HtmlForm server control for the page calls this method.

適用於

另請參閱