Export (0) Print
Expand All
0 out of 4 rated this helpful - Rate this topic

Control.RenderControl Method

Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.

[Visual Basic]
Public Sub RenderControl( _
   ByVal writer As HtmlTextWriter _
)
[C#]
public void RenderControl(
 HtmlTextWriter writer
);
[C++]
public: void RenderControl(
 HtmlTextWriter* writer
);
[JScript]
public function RenderControl(
   writer : HtmlTextWriter
);

Parameters

writer
The HtmlTextWriter object that receives the control content.

Remarks

If a server control's Visible property is set to true, this method determines whether tracing is enabled for the page. If so, it stores trace information associated with the control, and renders the server control content to the page.

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] 
' 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 | HtmlTextWriter

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