Export (0) Print
Expand All

Literal Class

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

For a list of all members of this type, see Literal Members.

System.Object
   System.Web.UI.Control
      System.Web.UI.WebControls.Literal

[Visual Basic]
Public Class Literal
   Inherits Control
[C#]
public class Literal : Control
[C++]
public __gc class Literal : public Control
[JScript]
public class Literal extends Control

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.

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   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, see Validation Server Controls.

Example

[Visual Basic, C#] The following example demonstrates how to use the Literal control to display static text.

[Visual Basic] 

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      Sub ButtonClick(sender As Object, e As EventArgs)
      
         Literal1.Text="Welcome to ASP.NET!!"
      
      End Sub

   </script>

</head>
<body>
   <form 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" %>

<html>
<head>

   <script runat="server">

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

   </script>

</head>
<body>
   <form 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++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI.WebControls

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web (in System.Web.dll)

See Also

Literal Members | System.Web.UI.WebControls Namespace | Label | Text

Show:
© 2014 Microsoft