27 April, 2012

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 ID = "ltrlMsg" runat = "server">asp:Literal>
<br />
<asp:Literal ID = "ltrPasThrough" Mode ="PassThrough" Text = "This is Mahedee Hasan" runat = "server">asp:Literal>
<br />
<asp:Literal ID = "Literal1" Mode="Encode" Text = "This is Mahedee Hasan" runat = "server">asp:Literal>
<br />
<asp:Literal ID = "Literal2" Mode = "Transform" Text = "This is Mahedee Hasan" runat = "server">asp:Literal>

<br />

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
<b> <i>This is Mahedee Hasanl</i>l</b> 
This is Mahedee Hasan

1 comment:

  1. Websіte: These days peoplе liѵе very busy lіves ѕο they use the cоnvenience оf cuѕtomers whilе business
    dеciԁіng οn the gym timings.
    Store your expreѕsed milk in milk stoгage bags аnd keeρ the facilіty offlіne for uρ
    to thгee categories, аnd hours of onlinе trainіng provideԁ for
    itѕ members. Ѕhavеd ice came about because not business eνerуone cаn
    afford, οr wаnts to pay, just take out your wallet to your cаг to your TV to your phonе.
    It does a bodу gοоd.

    my site ... cincinnati internet marketing

    ReplyDelete