Export (0) Print
Expand All

Page.RegisterViewStateHandler Method

Causes page view state to be persisted, if called.

[Visual Basic]
Public Sub RegisterViewStateHandler()
[C#]
public void RegisterViewStateHandler();
[C++]
public: void RegisterViewStateHandler();
[JScript]
public function RegisterViewStateHandler();

Remarks

If you do not call this method, the page will not calculate its view state. Server controls call this method to calculate the view state for their containing page. If this method is not called, the save-view-state stage of page processing is skipped.

Note   Typically, only the HtmlForm server control for the page calls this method.

Example

[Visual Basic] 
' 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


[C#] 
// 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();
   }
}

[C++] 
// Create a custom HtmlForm server control named MyForm. 
public __gc class MyForm : public HtmlForm
{
   // MyForm inherits all the base funcitionality
   // of the HtmlForm control.
public:
   MyForm(): HtmlForm()
   {
   }
   // Override the OnInit method that MyForm inherited from HtmlForm.

protected:
   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name=S"FullTrust")] 
   void OnInit( EventArgs* /*e*/)
   {
      // Save the view state if there are server controls on
      // a page that calls MyForm.
      Page->RegisterViewStateHandler();
   }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Page Class | Page Members | System.Web.UI Namespace

Show:
© 2014 Microsoft