-->

22 December 2019

Asp.Net Literal Control

  Asp.Net CS By Example       22 December 2019




  The Literal control :
     The Literal control is used to Displaying Information on web page. The Label control supports several additional formatting properties but the Literal control simply displays text.


Syntax:
<asp:literal ID="Literal1"  runat="server" Text="Welcome to Asp.net" />


The Literal control property :
S.N. Property Description
1) ID Set the uniqe value to control to access in code-behind code.
2) Text The error message displayed when validation fails.
3) Mode When click on label focus is automatically set in associte textfield control.

The Mode property enables we to encode HTML content and accepts any of the following three values:
  • PassThrough
  • —Displays the contents of the control without encoding.
  • Encode
  • —Displays the contents of the control after HTML encoding the content.
  • Transform
  • —Displays the contents of the control after stripping markup not supported by the requesting device.

    Code: LiteralcontrolDemo.aspx

    <<%@ 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">
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            PageTitle.Text = DateTime.Now.ToString("M");
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>
            <asp:Literal ID="PageTitle" runat="Server" /></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:Literal ID="Literal1" runat="server" Text="Welcome to Asp.net"  ></asp:Literal>
        <h1>
    				Look in the title bar</h1>
        </div>
        </form>
        
    </body>
    </html>
    
    
    

    Output:

    logoblog

    Thanks for reading Asp.Net Literal Control

    Previous
    « Prev Post