Page.VerifyRenderingInServerForm(Control) Page.VerifyRenderingInServerForm(Control) Page.VerifyRenderingInServerForm(Control) Method

定義

確認在 Run Time 時期呈現了所指定 ASP.NET 伺服器控制項的 HtmlForm 控制項。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

參數

control
Control Control Control

HtmlForm 控制項中的必要 ASP.NET 伺服器控制項。The ASP.NET server control that is required in the HtmlForm control.

例外狀況

指定的伺服器控制項在 Run Time 時期並不包含於 HtmlForm 伺服器控制項的開頭和結尾標記之間。The specified server control is not contained between the opening and closing tags of the HtmlForm server control at run time.

要驗證的控制項為 nullThe control to verify is null.

範例

下列程式碼會覆寫Page.Render自訂伺服器控制項的方法。The following code example overrides the Page.Render method of a custom server control. 當這個控制項將其內容寫入頁面時,它會使用VerifyRenderingInServerForm方法以確定控制項顯示的開頭和結尾標記之間HtmlForm控制項。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

備註

必須是內部的控制項<form runat=server>標記之前它們轉譯,讓它們被放外部標籤顯示錯誤訊息,可以呼叫這個方法。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. 回傳或取決於已註冊的指令碼區塊的控制項應該呼叫這個方法的覆寫中Control.Render方法。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.

如果不放在伺服器控制項的回傳,或使用用戶端指令碼將無法運作HtmlForm伺服器控制項 (<form runat="server">) 標記。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. 這些控制項可以呼叫這個方法,其提供明確的錯誤訊息,當不放在轉譯時HtmlForm控制項。These controls can call this method when they render to provide a clear error message when they are not enclosed in the HtmlForm control.

當您開發的自訂伺服器控制項時,通常會呼叫這個方法,當您覆寫Render為任何種類的輸入標記的方法。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. 這是特別重要,如果輸入的控制項會呼叫GetPostBackEventReference,則它會發出用戶端指令碼。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.

適用於