Literal.Render(HtmlTextWriter) Method

Definition

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

protected:
 override void Render(System::Web::UI::HtmlTextWriter ^ output);
protected public:
 override void Render(System::Web::UI::HtmlTextWriter ^ writer);
protected override void Render (System.Web.UI.HtmlTextWriter output);
protected internal override void Render (System.Web.UI.HtmlTextWriter writer);
override this.Render : System.Web.UI.HtmlTextWriter -> unit
override this.Render : System.Web.UI.HtmlTextWriter -> unit
Protected Overrides Sub Render (output As HtmlTextWriter)
Protected Friend Overrides Sub Render (writer As HtmlTextWriter)

Parameters

outputwriter
HtmlTextWriter

The HtmlTextWriter object that receives the server control content.

Examples

The following code example demonstrates how to override the Render method in a custom server control so that specific text is always displayed before the Literal.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom LiteralControl - Render - C# Example</title>
       <script runat="server">
      void Button1_Click(Object sender, EventArgs e)
      {
         Literal1.Text = "Welcome to ASP.NET!";
      }
   </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LiteralControl - Render - C# Example</h3>
            
            <aspSample:CustomLiteralRender id="Literal1" 
              runat="server" />

      <br /><br />

      <asp:Button id="Button1"
        Text="Change"
        OnClick="Button1_Click"
        runat="server"/>
        </form>
    </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom LiteralControl - Render - VB.Net Example</title>
       <script runat="server">
      Sub Button1_Click(sender As Object, e As EventArgs)
      
         Literal1.Text = "Welcome to ASP.NET!"

      End Sub
   </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LiteralControl - Render - VB.Net Example</h3>
            
            <aspSample:CustomLiteralRender id="Literal1" 
              runat="server" />

      <br /><br />

      <asp:Button id="Button1"
        Text="Change"
        OnClick="Button1_Click"
        runat="server"/>
        </form>
    </body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomLiteralRender : System.Web.UI.LiteralControl
  {
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
      // Write out some literal text.
      writer.Write("Literal Text: ");
      
      // Call the base Render method.
      base.Render(writer);
    }
  }
}
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomLiteralRender
    Inherits System.Web.UI.WebControls.Literal

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

        ' Write out some literal text.
        writer.Write("Literal Text: ")

        ' Call the base Render method.
        MyBase.Render(writer)
    End Sub
End Class

Applies to