Display information by ASP.net Literal Control

The literal control is similar to the Label control. Unlike the Label control, the Literal control does not render its content inside of a tag. You can use the Literal control to display text or HTML content in a browser.

Literal control does not support either CssClass or BackColor properties.

Literal control has mode property which Label has not.
Three mode property of Literal control:

  1. PassThrough: Displays the contents of the control without encoding.
  2. Encode: The contents of the control are converted to an HTML-encoded string.
  3. Transform: Unsupported markup-language elements are removed from the contents of the control. If the Literal control is rendered on a browser that supports HTML or XHTML, the control’s contents are not modified.

You will be clear after watching output of the following

Write the following code in your aspx page. Here I used 4 literal. 1st one for displaying simple message from code behind. Others 3 are displayed the content in different mode of literal.

asp:Literal>

asp:Literal>
asp:Literal>
asp:Literal>
protected void Page_Load(object sender, EventArgs e)
{
    this.ltrlMsg.Text = "Welcome to ASP.net Literal Control!";
}

The output of the code is look like this.
Welcome to ASP.net Literal Control!
This is Mahedee Hasan
This is Mahedee Hasanll
This is Mahedee Hasan

Please share, if it is helpfulShare on FacebookShare on LinkedInTweet about this on TwitterShare on Google+Email this to someonePrint this page

Leave a Reply

Your email address will not be published. Required fields are marked *