Mode property of Literal control in ASP.NET

October 07, 2013 0 Comments


A literal control contains three enumeration value such as PassThrough , Encode and Transform. Using these enumeration we can obtains or sets an enumeration value that specifies how the content in the Literal control is rendered (According to msdn).

Enumeration values of the Mode properties are:

PassThrough :  If you specify PassThrough in mode property, all contents of the Text property are passed to the browser without making any modifications. For example.

<asp:Literal ID="Literal1" runat="server" Mode ="PassThrough" Text ="<h1>Hello world</h1>" ></asp:Literal>


ASP.NET :PassThrough enumeration in mode property

Encode : If you specify Encode in mode property, the contents for the Text property are converted into an HTML-encoded string before rendering. For example, if the Text property of a Literal control contains an <H1> tag, it is converted to &lt;H1&gt; and sent to the  browser. (according to msdn article)

<asp:Literal Mode ="Encode" ID="Literal1" runat="server"  Text ="<h1>Hello world</h1>" ></asp:Literal>

ASP.NET: Encode enumeration in mode property of literal control

Transform : If you specify Transform, the rendering behavior of the Text property depends on the type of markup being rendered. When the Literal control is rendered for a device or browser that supports HTML or XHTML, specifying Transform produces the same behavior as specifying PassThrough.

  <asp:Literal Mode="Transform" ID="Literal1" runat="server"  Text ="<h1>Hello world</h1>" ></asp:Literal>

ASP.NET :Transform enumeration in mode property

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google