Export (0) Print
Expand All
0 out of 1 rated this helpful - 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.

[Visual Basic]
Protected Overridable Sub RenderChildren( _
   ByVal writer As HtmlTextWriter _
)
[C#]
protected virtual void RenderChildren(
 HtmlTextWriter writer
);
[C++]
protected: virtual void RenderChildren(
 HtmlTextWriter* writer
);
[JScript]
protected function RenderChildren(
   writer : HtmlTextWriter
);

Parameters

writer
The HtmlTextWriter object that receives the rendered content.

Remarks

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.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic, C#, C++] The overridden Render method then calls the overridden RenderChildren method.

[Visual Basic] 
' 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 'RenderChildren
      
      
      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


[C#] 
// 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);
}
   }

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

void Render(HtmlTextWriter* output)
{       
   output->Write(S"<br>Message from Control : {0}", Message);          
   output->Write(S"Showing Custom controls created in reverse order");         
   // Render Controls.
   RenderChildren(output);
}
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace | Render | RenderControl

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.