Control.Render Method Home
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.NET Framework Class Library
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 _
)
[C#]
protected virtual void Render(
 HtmlTextWriter writer
);
[C++]
protected: virtual void Render(
 HtmlTextWriter* writer
);
[JScript]
protected function Render(
   writer : HtmlTextWriter
);

Parameters

writer
The HtmlTextWriter object that receives the server control content.

Remarks

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.

Example

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

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

[C++] 
protected:
[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);
    }
}

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

Requirements

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

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View