Differences between Literal and label in asp.net

Source: Internet
Author: User

 

The difference between the Literal control and the Label control is that the Literal control does not add any HTML elements to the text. (The Label control presents a span element .) Therefore, the Literal control does not support any style attributes including position attributes. However, the Literal control allows you to specify whether to encode the content.

 

Encode content in the Literal control

The Literal control supports the Mode attribute, which is used to specify how the control handles the tags you have added. You can set the Mode attribute to the following values:

Transform. converts any tags added to the control to adapt to the protocol of the requesting browser. This setting is useful for rendering content to mobile devices that use other protocols other than HTML.

PassThrough. Any markup added to the control will be displayed in the browser as is.

Encode. The HtmlEncode method will be used to Encode any tag added to the control. This will convert HTML encoding into its text representation. For example, the <B> tag is displayed as & lt; B & gt ;. Encoding is useful when you want the browser to display without interpreting the mark. Encoding is also useful for security and helps prevent malicious tags from being executed in browsers. This setting is recommended when displaying strings from untrusted sources.

 

 

 

Literal cannot use styles. Location layout is troublesome.

You can add a Literal Web Server Control to the page when you want to set text programmatically without adding additional HTML tags. The Literal control is useful when you want to dynamically add text to a page without adding any elements that do not belong to the dynamic text. For example, you can use the Literal control to display the HTML read from a file or stream.

To display static text, you can use HTML to render it. The Literal control is not required. The Literal control is used only when the text needs to be rendered programmatically.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.