Page.RegisterViewStateHandler 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
呼叫時會使網頁檢視狀態被保存 (Persist)。
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 頁面的伺服器控制項會呼叫這個方法。