ASP.Net: Literal vs Label

后端 未结 4 867
无人及你
无人及你 2020-12-07 10:12

I just wanted to hear some authorities on when and where you should use a LITERAL control over a LABEL.

As I understand it, the difference

4条回答
  •  北海茫月
    2020-12-07 10:58

    Yep, the main difference is that Literal controls just render out text, but Label controls surround it with tags (Unless you use the AssociatedControlID property, in which case a Label control will render a tag).

    So, labels can be styled easier, but if you're just inserting text, literals are the way to go. Literal controls also have a handy property Mode which governs how the text is rendered. You can have it HTML-encoded, or rendered without any changes, or have any "unsupported markup-language elements" removed.

    If you're not applying any styles (e.g. by using Label's CssClass property), it will be fine to replace Label controls with Literal controls.

提交回复
热议问题