Control.RenderChildren(HtmlTextWriter) 方法

定义

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,该对象可写入要在客户端上呈现的内容。

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

参数

writer
HtmlTextWriter

接收呈现的内容的 HtmlTextWriter 对象。

示例

以下示例替代 RenderChildren 自定义服务器控件中的 方法。 它确定当前控件在其 ControlCollection 对象中是否具有任何子控件。 如果存在,则使用 Count 属性循环访问集合。 当它遇到每个子控件时,它使用 RenderControl 方法将父控件及其所有子控件呈现到包含页。

Render重写的方法随后调用重写RenderChildren的方法。

// Override default implementation to Render children according to needs. 
protected override void RenderChildren(HtmlTextWriter output)
{
   if (HasControls())
   {
      // Render Children in reverse order.
      for(int i = Controls.Count - 1; i >= 0; --i)
      {
         Controls[i].RenderControl(output);
      }
   }         
}

protected override void Render(HtmlTextWriter output)
{       
   output.Write("<br>Message from Control : " + Message);       
   output.Write("Showing Custom controls created in reverse" +
                                                    "order");         
   // Render Controls.
   RenderChildren(output);
}
' Override default implementation to Render children according to needs. 
      Protected Overrides Sub RenderChildren(output As HtmlTextWriter)
         If HasControls() Then
            ' Render Children in reverse order.
            Dim i As Integer

            For i = Controls.Count - 1 To 0 Step -1
               Controls(i).RenderControl(output)
            Next

         End If
      End Sub
      
      
      Protected Overrides Sub Render(output As HtmlTextWriter)
         output.Write(("<br>Message from Control : " + Message))
         output.Write(("Showing Custom controls created in reverse" + "order"))
         ' Render Controls.
         RenderChildren(output)
      End Sub
   End Class

注解

此方法通知 ASP.NET 在页面上呈现任何 Active Server Pages (ASP) 代码。 如果页面上不存在 ASP 代码,此方法将呈现服务器控件的任何子控件。 此方法由 Render 方法调用。

适用于

另请参阅