Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Control.RenderChildren Method

Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
protected internal virtual void RenderChildren (
	HtmlTextWriter writer
)
protected void RenderChildren (
	HtmlTextWriter writer
)
protected internal function RenderChildren (
	writer : HtmlTextWriter
)
Not applicable.

Parameters

writer

The HtmlTextWriter object that receives the rendered content.

This method notifies ASP.NET to render any Active Server Pages (ASP) code on the page. If no ASP code exists on the page, this method renders any child controls for the server control.

The following example overrides the RenderChildren method in a custom server control. It determines whether the current control has any child controls in its ControlCollection object. If it does, it uses the Count property to iterate through the collection. As it encounters each child control, it uses the RenderControl method to render the parent control, and all of its child controls, to the containing page.

The overridden Render method then calls the overridden RenderChildren method.

// 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);
}

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.