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

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

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