Control.Render(HtmlTextWriter) Control.Render(HtmlTextWriter) Control.Render(HtmlTextWriter) Control.Render(HtmlTextWriter) Method

定義

將伺服器控制項內容傳送到提供的 HtmlTextWriter 物件,以寫入要在用戶端上呈現的內容。Sends server control content to a provided HtmlTextWriter object, which writes the content to be rendered on the client.

protected public:
 virtual void Render(System::Web::UI::HtmlTextWriter ^ writer);
protected internal virtual void Render (System.Web.UI.HtmlTextWriter writer);
abstract member Render : System.Web.UI.HtmlTextWriter -> unit
override this.Render : System.Web.UI.HtmlTextWriter -> unit
Protected Friend Overridable Sub Render (writer As HtmlTextWriter)

參數

writer
HtmlTextWriter HtmlTextWriter HtmlTextWriter HtmlTextWriter

接收伺服器控制項內容的 HtmlTextWriter 物件。The HtmlTextWriter object that receives the server control content.

範例

下列程式碼範例示範如何覆寫Render方法。The following code example demonstrates overriding the Render method. HasControls方法用來判斷伺服器控制項是否具有任何子控制項,儲存在其ControlCollection物件,可透過存取Control.Controls屬性。The HasControls method is used to determine whether the server control has any child controls stored in its ControlCollection object, which is accessible through the Control.Controls property. 如果HasControls傳回 true,而且集合中的第一個伺服器控制項是常值文字,則常值的文字附加至 HTML 字串。If HasControls returns true and the first server control in the collection is literal text, then the literal text is appended to an HTML string.

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
protected override void Render(HtmlTextWriter output) {
    if ( (HasControls()) && (Controls[0] is LiteralControl) ) {
        output.Write("<H2>Your Message: " + ((LiteralControl) Controls[0]).Text + "</H2>");
    }
}
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub Render(Output As HtmlTextWriter)
    If HasControls() And TypeOf Controls(0) Is LiteralControl
        Dim Ctrl As LiteralControl = CType(Controls(0), LiteralControl)
        Output.Write("<H2>Your Message: " & Ctrl.Text & "</H2>")
    End If
End Sub

備註

在開發自訂伺服器控制項時,您可以覆寫這個方法,以產生 ASP.NET 網頁的內容。When developing custom server controls, you can override this method to generate content for an ASP.NET page.

適用於

另請參閱