This documentation is archived and is not being maintained.

Control.Render Method

Sends server control content to a provided HtmlTextWriter object, which writes the content to be rendered on the client.

[Visual Basic]
Protected Overridable Sub Render( _
   ByVal writer As HtmlTextWriter _
protected virtual void Render(
 HtmlTextWriter writer
protected: virtual void Render(
 HtmlTextWriter* writer
protected function Render(
   writer : HtmlTextWriter


The HtmlTextWriter object that receives the server control content.


When developing custom server controls, you can override this method to generate content for an ASP.NET page. For more information, see Methods in ASP.NET Server Controls.


The following example overrides the Render method, using the HasControls method to determine whether the server control has any child controls stored in its ControlCollection object, which is accessible through the Control.Controls property. If so, it determines whether the first server control in the collection is literal text. If both conditions are met, the literal text is appended to an HTML string.

[Visual Basic] 
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub Render(Output As HtmlTextWriter)
    If HasControls() And TypeOf Controls(0) Is LiteralControl
        Dim Ctrl As LiteralControl = CType(Controls(0), LiteralControl)
        Output.Write("<H2>Your Message: " & Ctrl.Text & "</H2>")
    End If
End Sub

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
protected override void Render(HtmlTextWriter output) {
    if ( (HasControls()) && (Controls[0] is LiteralControl) ) {
        output.Write("<H2>Your Message: " + ((LiteralControl) Controls[0]).Text + "</H2>");

[System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name=S"FullTrust")] 
void Render(HtmlTextWriter* output) {
    if ( (HasControls()) && dynamic_cast<LiteralControl*>(Controls->Item[0] )) {
        output->Write(S"<H2>Your Message: {0}</H2>", (dynamic_cast<LiteralControl*>(Controls->Item[0]))->Text);

protected override function Render(output : HtmlTextWriter) {
var securityperm : SecurityPermission;
         securityperm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
    if ( (HasControls()) && (typeof(Controls[0]) == LiteralControl) ) {
        output.Write("<H2>Your Message: " + (LiteralControl(Controls[0])).Text + "</H2>");


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

See Also

Control Class | Control Members | System.Web.UI Namespace | HtmlTextWriter | Control Execution Lifecycle | Methods in ASP.NET Server Controls