表示在网页上显示文本的标签控件。
命名空间:System.Web.UI.WebControls
程序集:System.Web(在 system.web.dll 中)
<ControlValuePropertyAttribute("Text")> _
Public Class Label
Inherits WebControl
Implements ITextControl
[ControlValuePropertyAttribute("Text")]
public class Label : WebControl, ITextControl
[ControlValuePropertyAttribute(L"Text")]
public ref class Label : public WebControl, ITextControl
/** @attribute ControlValuePropertyAttribute("Text") */
public class Label extends WebControl implements ITextControl
ControlValuePropertyAttribute("Text")
public class Label extends WebControl implements ITextControl
使用 Label 控件在网页的设置位置上显示文本。不像静态文本,可以通过 Text 属性自定义显示文本。
也可以使用 Literal 和 PlaceHolder 控件在 Web 窗体页上显示文本。但与 Label 控件不同的是,这些控件不会呈现任何附加标记。
辅助功能
默认情况下为此控件呈现的标记可能不符合 Web 内容辅助功能准则 1.0 (WCAG) 中优先级为 1 的准则等辅助功能标准。有关此控件的辅助功能支持的详细信息,请参见 ASP.NET 控件和辅助功能。
下面的示例说明如何在网页上创建 Label 控件。
注意 |
|---|
| 下面的代码示例使用单文件代码模型,当它直接复制到代码隐藏文件时可能不能正常工作。此代码示例必须被复制到具有 .aspx 扩展名的空文本文件中。有关 Web 窗体代码模型的更多信息,请参见 ASP.NET 网页代码模型。 |
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script language="VB" runat="server">
Sub Button_Click(Sender As Object, e As EventArgs)
Label1.Text = Server.HtmlEncode(Text1.Text)
End Sub
</script>
</head>
<body>
<form id="Form1" runat="server">
<h3>Label Example</h3>
<asp:Label id="Label1"
Text="Label Control"
runat="server"/>
<p>
<asp:TextBox id="Text1"
Text="Copy this text to the label"
Width="200px"
runat="server" />
<asp:Button id="Button1"
Text="Copy"
OnClick="Button_Click"
runat="server"/>
</p>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
void Button_Click(Object Sender, EventArgs e)
{
Label1.Text = Server.HtmlEncode(Text1.Text);
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<h3>Label Example</h3>
<asp:Label id="Label1"
Text="Label Control"
runat="server"/>
<p>
<asp:TextBox id="Text1"
Text="Copy this text to the label"
Width="200px"
runat="server" />
<asp:Button id="Button1"
Text="Copy"
OnClick="Button_Click"
runat="server"/>
</p>
</form>
</body>
</html>
System.Object
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.Label
System.Web.UI.WebControls.BaseValidator
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0、1.1、1.0