|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Literal Web Server Control Overview
You can use aWeb server control as a container for other content on the page. The Literal control is used most frequently when adding content dynamically to the page.
The Literal control represents one of several options for adding content to a page. For static content, you can add markup directly to a page as HTML, without using a container. However, if you want to add content dynamically, you must add the content to a container. Typical containers are thecontrol, the Literal control, the control, and the control.
The Literal control differs from the Label control in that the Literal control does not add any HTML elements to the text. (The Label control renders a span element.) As a consequence, the Literal control does not support any style attributes, including position attributes. However, the Literal control allows you to specify whether content is encoded.
The Panel and Placeholder controls render as div elements, which create discrete blocks in the page, unlike rendering in-line the way the Label and Literal controls do.
In general, use a Literal control when you want to render text and controls directly into a page without any additional markup.
The Literal control supports theproperty, which specifies how the control handles markup that you add to it. You can set the Mode property to these values:
. 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.
. Any markup you add to the control is rendered as-is to the browser.
. Any markup you add to the control is encoded using the method, which converts HTML encoding into its text representation. For example, a
<b>tag is rendered as
<b>. Encoding is useful when you want the browser to display markup rather than interpret it. Encoding is also useful for security, to help prevent malicious markup from being executed in the browser, and is recommended if you are displaying strings from an untrusted source. For more information, see .