Literal Control in ASP.Net
Literal control is used to write simple text on the page, you can use server
side formatting options like bold, italic, underlined.
We cannot change its appearance as in Label .Unlike asp:label control,
there is no property like
etc. of Literal control.
Difference between Label
Control and Literal Control
The main difference is, you
can apply style to a Label control where as you can not apply styles in a
Label control renders as span
tag in a webpage while Literal Control only shows the text without any tag
associated to it.
Literal control does not
maintain its viewstate.
ASP.NET Literal itself is a
class which is present under System.Web.UI namespace.
Literal Mode property:
PassThrough: If you
set this property, then the content will not be modified and rendered as is. For
eg., if string contains <hr> tag then its dependent on your browser, of how it
handles <hr> tag.
Encode: If you set
this property then content will be encoded and sent to browser for e.g., if your
string contains <hr> tag, then your string will be converted to <Hr> and
sent to browser.
Transform: If you set
Mode property to Transform then the string render depends upon the type of the
sender, EventArgs e)
Literal1.Text = "<hr>Hello from literal";
Literal2.Text = "<hr>hr tag enclosed with mode PassThrough";
Literal3.Text = "<hr>hr tag enclosed with mode Encode";