什么是用于文字控制和有什么区别在asp.net Label控件? [英] What's the Literal control used for and what's the difference to the Label Control in asp.net?

查看:143
本文介绍了什么是用于文字控制和有什么区别在asp.net Label控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net是用来做什么文字控制?而这也正是他们和Label控件之间的区别?

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

推荐答案

的主要区别是,在标签控制添加span标签您设置的文本(财产),允许应用样式它:

The major difference is that the Label Control adds the span tag to the text (property) you set, allowing to apply a style to it:

<span>My Label text</span>

文字控制,您可以使任何类型的内容。可以用它来渲染脚本,HMTL以及任何其他类型的文件的内容。它不会改变你的Text属性提供的字符串。

The Literal Control allows you to render any kind of content. You can use it to render scripts, hmtl and any other type of document content. It doesn't change the string you provide in the Text property.

注:Label控件,您可以直接呈现HTML太多,但提到它把所有的文本span标签。因此,对于大型渲染HTML部分的文字控制是要走的路。

P.S: HTML 的有一个&LT;标签&gt; 标记。如果使用Label控件的 AssociatedControlId 属性,则呈现为HTML &LT;标签&gt; (感谢雷指出了这一点。)

P.S.: In HTML there is a <label> tag. If you use the AssociatedControlId property of the Label control, it will render as HTML <label> (thanks to Ray for pointing that out.)

例如:

<asp:Label runat="server" id="FirstNameLabel" AssociatedControlId="FirstNameTextBox">
Input First Name:
</asp:Label>
<asp:Textbox runat="server" id="FirstNameTextBox" />

会渲染:

<label for="FirstNameTextbox" id="FirstNameLabel">Input first name:</label>
<input type="text" id="FirstNameTextbox" name="FirstNameTextBox" />

也在这里在W3学校请参见

See also here on W3 Schools.

这篇关于什么是用于文字控制和有什么区别在asp.net Label控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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