System.Web.UI.WebControls N ...


.NET Framework Class Library
Literal Class

Reserves a location on the Web page to display static text.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Syntax

Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Literal _
    Inherits Control _
    Implements ITextControl
Visual Basic (Usage)
Dim instance As Literal
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Literal : Control, ITextControl
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Literal : public Control, 
    ITextControl
JScript
public class Literal extends Control implements ITextControl
ASP.NET
<asp:Literal />
Remarks

Use the System.Web.UI.WebControls..::.Literal control to reserve a location on the Web page to display text. The Literal control is similar to the Label control, except the Literal control does not allow you to apply a style to the displayed text. You can programmatically control the text displayed in the control by setting the Text property.

Caution noteCaution:

This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input.

For more information about security, see Securing Standard Controls, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Validating User Input in ASP.NET Web Pages.

TopicLocation
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications in Visual Studio
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications in Visual Studio
How to: Add Literal Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Literal Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Literal Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
How to: Add Literal Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
How to: Add Literal Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Add PlaceHolder Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add PlaceHolder Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Rows and Cells Dynamically to a Table Web Server ControlBuilding ASP .NET Web Applications
How to: Add Rows and Cells Dynamically to a Table Web Server ControlBuilding ASP .NET Web Applications
How to: Add Rows and Cells Dynamically to a Table Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Add Rows and Cells Dynamically to a Table Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding Applications with Visual Web Developer
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
Examples

The following example demonstrates how to use the Literal control to display static text.

NoteNote:

The following example uses the single-file code model and might not work correctly if copied directly into a code-behind file. This code example must be copied into an empty text file that has an .aspx extension. For more information about the Web Forms code model, see ASP.NET Web Page Code Model.

Visual Basic
<%@ 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  >
<head>
    <title>Literal Example</title>
<script runat="server">

      Sub ButtonClick(sender As Object, e As EventArgs)

         Literal1.Text="Welcome to ASP.NET!!"

      End Sub

   </script>

</head>
<body>
   <form id="form1" runat="server">
      <h3>Literal Example</h3>

      <asp:Literal id="Literal1"
           Text="Hello World!!"
           runat="server"/>

      <br /><br />

      <asp:Button id="Button1"
           Text="Change Literal Text"
           OnClick="ButtonClick"
           runat="server"/>

   </form>
</body>
</html>

C#
<%@ 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  >
<head>
    <title>Literal Example</title>
<script runat="server">

      void ButtonClick(Object sender, EventArgs e)
      {
         Literal1.Text="Welcome to ASP.NET!!";
      }

   </script>

</head>
<body>
   <form id="form1" runat="server">
      <h3>Literal Example</h3>

      <asp:Literal id="Literal1"
           Text="Hello World!!"
           runat="server"/>

      <br /><br />

      <asp:Button id="Button1"
           Text="Change Literal Text"
           OnClick="ButtonClick"
           runat="server"/>

   </form>
</body>
</html>

.NET Framework Security

Inheritance Hierarchy

System..::.Object
  System.Web.UI..::.Control
    System.Web.UI.WebControls..::.Literal
      System.Web.UI.WebControls..::.Localize
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Other Resources

Tags :


Community Content

Anthony Berglas
Warning Litteral does NOT HtmlEscape (Amazingly)
This needs to be said explicitly, not like the vague caution. Is there a control that does HTML escape? Or do I need to write this most basic thing myself?
Tags :

Page view tracker