ASP.Net:文字VS标签 [英] ASP.Net: Literal vs Label

查看:149
本文介绍了ASP.Net:文字VS标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关不可思议newbish问题道歉,但我只是想听听你对的时候,有些部门,你应该使用超过标签的 LITERAL 控制

Apologies for the incredible newbish question, but I just wanted to hear some authorities on when and where you should use a LITERAL control over a LABEL.

据我了解,所不同的是:A LABEL 可以通过风格的< SPAN> 被添加标签。

As I understand it, the difference is this: A LABEL can be styled via the <SPAN> tags that are added.

我个人觉得加入&LT; SPAN&GT; 在我的HTML标签很烦人,从来没有真正通过ASP应用样式,所以 LITERAL 取值似乎应该用什么大部分时间......但我担心还有的其他的考虑或利益使用LABEL了它,我是不知道。

I personally find the addition of <SPAN> tags in my HTML to be very annoying and never actually apply styles through ASP, and so LITERALs seem to be what should be used most of the time... but I'm concerned there's other considerations or benefits to using a LABEL over it that I'm unaware of.

它是完全罚款与 LITERAL S,更换任何 LABEL s提供我们'100%再没有应用样式给他们?难道没有其他的考虑?

Is it 100% completely fine to replace any LABELs with LITERALs, provided we're not applying styles to them? Are there NO other considerations?

感谢您的任何建议。

推荐答案

是的,主要的区别是,文字控件只呈现出文本,但标签控制环绕它与&LT;跨度&GT; 标签(除非你使用 AssociatedControlID 财产,在这种情况下,标签控件会呈现一个&LT;标签&gt; 标记)

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

因此​​,标签可以样式更容易,但如果你只是插入文本,文字是要走的路。文字控制也有一个方便的特性<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.mode.aspx\"><$c$c>Mode指导该文本的呈现方式。你可以把它HTML-CN codeD,或没有任何变化呈现,或有任何不支持的标记语言元素中删除。

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.

如果你没有应用任何样式(例如,通过使用标签的CssClass 属性),它会罚款与文字控件来替换标签控制。

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.

这篇关于ASP.Net:文字VS标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆