What is LiteralControl? Why is it used?

前端 未结 7 2393
暖寄归人
暖寄归人 2020-12-15 06:11

What is a LiteralControl? I was reading about LiteralContols but I am not sure why they are used. I used this code to list the controls in a page and - I have

7条回答
  •  猫巷女王i
    2020-12-15 06:32

    A lot of programmers who don't understand the value of semantic markup (especially those with primarily a Windows Forms background) will use a Label control or the HTML LABEL tag as a placeholder for programmatically-generated text on a page. The disadvantage to this is that Label has semantic meaning in an HTML document.

    Using a literal gives you a control with an ID attribute to hook to, while allowing you to inject semantically correct markup around it.

    Additionally, if you end up not pushing any text to a LABEL tag, it will still output the tag in your HTML, like so: , whereas a Literal with no text will output nothing - much cleaner.

提交回复
热议问题