Literal control in ASP.NET using VB.NET

This article shows the literal control and also defines the difference with label control in ASP.NET.
  • 9555

Literal Control

The Literal control is similar to the Label control, except the Literal control does not enable you to apply a style to the displayed text.

Literal property:

The Literal control supports the Mode property which specifies how the control handles markup. Mode property can be three type.

literal1.gif
 

Figure 1.

Transform mode

Any markup you add to the control is transformed to accommodate the protocol of the requesting browser. This setting is useful if you are rendering content to mobile devices that use protocol other than HTML.  

PassThrough mode

Any markup you add to the control is rendered as-is to the browser.

Encode mode

Any markup you add to the control is encoded using the HtmlEncode method, which converts HTML encoding into its text representation. For example, a < b > tag is rendered as &lt;b&gt;. Encoding is useful when you want the browser to display markup rather than interpret it. Encoding is also useful for security.

How to use literal.aspx (Design Page).

literal 2.gif
 

Figure 2.

How to use literal.aspx (Source Page).

literal 3.gif
 

Figure 3.

How to use literal.aspx (View in Browser).

literal 4.gif
 

Figure 4.

Difference between a Literal Control and a Label Control:

Literal Control

A Literal Web Server control used to insert static text on a web page. The Literal Control's only controllable aspect is the text that it holds.

Label Control

The Label Web Server control is used to display static text on web page. The Label Control has properties that enable one to programmatically apply styles/stylesheet class to the rendered output. Can handle JavaScript at Client side.

Literal Control

The class hierarchy for this control is as follows:

Object ->Control ->Literal

Label Control

The class hierarchy for this control is as follows:

Object ->Control ->WebControl ->Label

Literal Control

Literal Control doesn't add any HTML elements to the web page

Label Control

Label Control is rendered as <span> tag.
You can't apply any style property to the Literal Control.
You can apply any style property to the Label Control.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.