Control.RenderControl Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Outputs server control content and stores tracing information about the control if tracing is enabled.
Overloads
RenderControl(HtmlTextWriter) |
Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled. |
RenderControl(HtmlTextWriter, ControlAdapter) |
Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object. |
RenderControl(HtmlTextWriter)
Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.
public:
void RenderControl(System::Web::UI::HtmlTextWriter ^ writer);
public:
virtual void RenderControl(System::Web::UI::HtmlTextWriter ^ writer);
public void RenderControl (System.Web.UI.HtmlTextWriter writer);
public virtual void RenderControl (System.Web.UI.HtmlTextWriter writer);
member this.RenderControl : System.Web.UI.HtmlTextWriter -> unit
abstract member RenderControl : System.Web.UI.HtmlTextWriter -> unit
override this.RenderControl : System.Web.UI.HtmlTextWriter -> unit
Public Sub RenderControl (writer As HtmlTextWriter)
Public Overridable Sub RenderControl (writer As HtmlTextWriter)
Parameters
- writer
- HtmlTextWriter
The HtmlTextWriter object that receives the control content.
Examples
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 child control, and all of its child controls, to the containing page. The XhtmlTextWriter object that is passed to this method is instantiated by the Render 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);
}
' 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
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.
This method is automatically called by the page during the rendering, but can be overridden by custom control developers.
See also
Applies to
RenderControl(HtmlTextWriter, ControlAdapter)
Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.
protected:
void RenderControl(System::Web::UI::HtmlTextWriter ^ writer, System::Web::UI::Adapters::ControlAdapter ^ adapter);
protected void RenderControl (System.Web.UI.HtmlTextWriter writer, System.Web.UI.Adapters.ControlAdapter adapter);
member this.RenderControl : System.Web.UI.HtmlTextWriter * System.Web.UI.Adapters.ControlAdapter -> unit
Protected Sub RenderControl (writer As HtmlTextWriter, adapter As ControlAdapter)
Parameters
- writer
- HtmlTextWriter
The HtmlTextWriter that receives the control content.
- adapter
- ControlAdapter
The ControlAdapter that defines the rendering.
Remarks
ASP.NET Web pages are usable across a wide range of devices and browsers that can request information from the Web. The Adapter property returns the ControlAdapter object that renders the control on the requesting device or browser's screen.
For more information about adapters, see Architectural Overview of Adaptive Control Behavior.
If a server control's Visible property is set to true
and tracing is enabled for the page, then trace information associated with the control is captured.
Notes to Inheritors
When overriding the RenderControl(HtmlTextWriter, ControlAdapter) method in custom controls, call the base class method to ensure trace information is correctly captured.