Literal.Mode Property
The "Mode" Property of Literal Control specifies an enumeration value that decides how the content in the Literal control is rendered
This property is set using one of the LiteralMode enumeration values. The following lists the possible values:
1. PassThrough: The contents of the control are not modified.
2. Encode: The contents of the control are converted to an HTML-encoded string.
3. Transform: Unsupported markup-language elements are removed from the contents of the control. If the Literal control is rendered on a browser that supports HTML or XHTML, the control's contents are not modified.
If you specify PassThrough, the entire contents of the Text property are passed to the device or browser without making any modifications. For example, if the Text property of a Literal control contains an <hr> tag, it is sent to all devices and browsers whether it is supported or not.
If you specify Encode, 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 <hr> tag, it is converted to <Hr> and sent to the device or browser.
If you specify Transform, the unsupported markup elements will be removed. In this case, any markup language elements of the Text property that are not supported in the targeted markup language are not rendered for the control. For example, if an unsupported tag contains content, only the tag is removed and the content is sent to the device or browser. For example, if the Text property contains the content <XYZ>Test</XYZ>, the <XYZ> and </XYZ> tags are removed, and the text "Test" is sent to the device or browser.
Example:
PassThrough: Entire content in the Text Property of Literal will be parsed and rendered in Browser without any modification.
<asp:Literal
id="ltlFirst"
Mode="PassThrough"
Text="<hr />"
Runat="server" />
Encode: Entire content in the Text Property of Literal will be converted into HTML-encoded string.
<asp:Literal
id="ltlSecond"
Mode="Encode"
Text="<hr />"
Runat="server" />
Transform: Entire content in the Text Property of Literal will be redered after removing unsupported elements.
<asp:Literal
id="ltlThird"
Mode="Transform"
Text="<XYZ><hr /></XYZ>"
Runat="server" />