What's the Literal control used for and what's the difference to the Label Control in asp.net?

后端 未结 7 1918
耶瑟儿~
耶瑟儿~ 2021-01-04 02:06

What Literal control is used for in asp.net? and What is the difference between them and Label control?

相关标签:
7条回答
  • 2021-01-04 02:35

    One thing also to note is if you are justing using it to display something and have no need for formatting the text use a Literal control. The ViewState is not as heavy with a Literal vs a Label control and when you have many of these on a page using ViewState it can really bloat your page size.

    I always ask myself, do I need to apply a custom style or formatting? Yes, use a Label. No, use a Literal.

    0 讨论(0)
  • 2021-01-04 02:37

    The label control also has the AssociatedControlId property that associates the label with another control. An example of where this is useful is with a textbox control. Once these are associated, screen readers are more able to give better results.

    Another example is a radio button with a label allows you to click on the label and the radiobutton will select if the AssociatedControlId property is set.

    MSDN on AssoicatedControlId

    0 讨论(0)
  • 2021-01-04 02:43

    It is used to display text on the page, the text that is displayed can be set at runtime via server side code.

    0 讨论(0)
  • 2021-01-04 02:43
    • We can use literal control in the title tag whereas label cannot be used in the title tag
    • Label can be used to set focus on other controls like Textbox. Whereas Literal simply rander the static text on the web page
    0 讨论(0)
  • 2021-01-04 02:54

    It will place LITERALLY whatever text you place in it on the page. You can use it to write html, JavaScript or just plain text.

    0 讨论(0)
  • 2021-01-04 02:55

    As splattne mentions, the label encloses its text in a span, whereas the literal is simply a placeholder. However, be careful in making assumptions about how ASP.Net controls are going to render. It can depend on the user agent that you are using. For instance, the panel control renders as a div in IE, but renders as a table with Firefox.

    0 讨论(0)
提交回复
热议问题