This documentation is archived and is not being maintained.

Adding Literal Web Server Controls to a Web Forms Page

Add a Literal Web server control to your page when you want to set text programmatically without adding extra HTML tags.

Note   If you want to display static text, you can present it using HTML; you do not need a Literal control. Use a Literal control only if you need to change the contents in server code.

To add a Literal control to a Web Forms page

  1. In Design view, drag a Literal control from the Web Forms tab of the Toolbox onto the page.

    The following example shows a simple page that displays a headline at run time. The body of the page, including the Literal control, might look like this:

       <form runat="server">
          <H1><asp:Literal id="Headline" runat=server /></H1>
  2. Add code to your page to set the control's Text property at run time.

    The following example shows how to programmatically set the text of the Literal control.

    ' Visual Basic
    Sub Page_Load(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles MyBase.Load
       Headline.Text = "New Web Site Announced"
    End Sub
    // C#
    private void Page_Load(object sender, System.EventArgs e)
       Headline.Text = "New Web Site Announced";

See Also

Introduction to the Literal Web Server Control | Literal Web Server Control | Literal Class