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)


HtmlTextWriter HtmlTextWriter HtmlTextWriter HtmlTextWriter

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


下列程式碼範例將示範如何Render覆寫方法。The following code example demonstrates overriding the Render method. 方法是用來判斷伺服器控制項是否有任何子控制項儲存在其ControlCollection物件中, Control.Controls這可透過屬性存取。 HasControlsThe 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.