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. 方法用于确定服务器控件是否具有存储在其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.

适用于

另请参阅