Export (0) Print
Expand All
Expand Minimize

Literal Web Server Control Declarative Syntax

Displays static contents on the page and allows you to manipulate it programmatically.

    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"

Use the Literal control to display static text on the Web Forms page. Unlike the Label control, Literal does not let you apply styles to its content.


Text is not HTML encoded before it is displayed in the Literal control. This makes it possible to embed script within HTML tags in the text. If the values for the control come from user input, be sure to validate the values to help prevent security vulnerabilities.

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

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>Literal Example</title>
<script runat="server">

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


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

      <asp:Literal id="Literal1"
           Text="Hello World!!"

      <br /><br />

      <asp:Button id="Button1"
           Text="Change Literal Text"


Community Additions

© 2014 Microsoft