Επεξεργασία

Κοινή χρήση μέσω


Page.VerifyRenderingInServerForm(Control) Method

Definition

Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.

public:
 virtual void VerifyRenderingInServerForm(System::Web::UI::Control ^ control);
public virtual void VerifyRenderingInServerForm (System.Web.UI.Control control);
abstract member VerifyRenderingInServerForm : System.Web.UI.Control -> unit
override this.VerifyRenderingInServerForm : System.Web.UI.Control -> unit
Public Overridable Sub VerifyRenderingInServerForm (control As Control)

Parameters

control
Control

The ASP.NET server control that is required in the HtmlForm control.

Exceptions

The specified server control is not contained between the opening and closing tags of the HtmlForm server control at run time.

The control to verify is null.

Examples

The following code example overrides the Page.Render method of a custom server control. When this control writes its content to a page, it uses the VerifyRenderingInServerForm method to make sure that the control appears between the opening and closing tags of an HtmlForm control.

// Override the Render method to ensure that this control
// is nested in an HtmlForm server control, between a <form runat=server>
// opening tag and a </form> closing tag.
protected override void Render(HtmlTextWriter writer) {
    // Ensure that the control is nested in a server form.
    if (Page != null) {
        Page.VerifyRenderingInServerForm(this);
    }
    base.Render(writer);
}
' Override the Render method to ensure that this control
' is nested in an HtmlForm server control, between a <form runat=server>
' opening tag and a </form> closing tag.
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

    ' Ensure that the control is nested in a server form.
    If Not (Page Is Nothing) Then
        Page.VerifyRenderingInServerForm(Me)
    End If

    MyBase.Render(writer)

End Sub

Remarks

Controls that are required to be inside <form runat=server> tags can call this method before they render so that an error message is shown if they are placed outside the tags. Controls that post back or depend on registered script blocks should call this method in an override of the Control.Render method. Pages that have a different way of rendering the server form element can override this method to throw an exception under different conditions.

Server controls that post back or use client-side script will not work if they are not enclosed in the HtmlForm server control (<form runat="server">) tags. These controls can call this method when they render to provide a clear error message when they are not enclosed in the HtmlForm control.

When you develop a custom server control, it is common to call this method when you override the Render method for any kind of input tag. This is particularly important if the input control calls GetPostBackEventReference, or if it emits client script. A composite server control does not need to make this call.

Applies to