Search Engine

Thursday, May 20, 2010

ASP.Net Literal Control

The ASP.Net Literal Control provides the functionality to reserve the space on the web page to display the static text. It is similar to the ASP.Net Label control that enables you to display the text on the page. You can display the text by specifying it in the HTML source code of Literal control or programmatically by assigning the text value to its Text property using C# or VB code at server side. Unlike Label control the Literal control does not provide the inbuilt CSS based style properties to customize the look and appearance of the text displayed by it. Instead it allows you to display the plain text as well as HTML formatted text and other client side scripts. You can also display the user input on the web page by assigning that value to the Literal control programmatically. As the Literal control can render scripts also it is recommended to validate the user input before rendering it dynamically using Literal control as the user input may contain malicious scripts that could be vulnerable.

Properties of Literal Control

Following are the two main properties of the ASP.Net Literal control that enable you to control its output behavior while displaying the text on the web page dynamically:

1. Mode: It accepts the predefined enumeration values as Literal modes that enable you to control the rendering behavior of the content specified to be displayed on the web page.

2. Text: You can specify the content to the Text property of the Literal control that you want to display on the web page. The Text property can be declared either in the HTML markup code block of the Literal control or programmatically in the code behind.

Sample Code for ASP.Net Literal Control

C# Sample Code:

Literal1.Text = "Text specified dynamically.";

You can also assign the text value programmatically at page load or any event to the Text property of the Literal control as shown in the above sample code.


Post a Comment