请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
.NET Framework
Label 类

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2008/.NET Framework 3.5

同时提供下列产品的其他版本:
.NET Framework 类库
Label 类

更新:2007 年 11 月

表示在网页上显示文本的标签控件。

命名空间:  System.Web.UI.WebControls
程序集:  System.Web(在 System.Web.dll 中)

Visual Basic(声明)
<ControlValuePropertyAttribute("Text")> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Label _
    Inherits WebControl _
    Implements ITextControl
Visual Basic (用法)
Dim instance As Label
C#
[ControlValuePropertyAttribute("Text")]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Label : WebControl, ITextControl
Visual C++
[ControlValuePropertyAttribute(L"Text")]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Label : public WebControl, 
    ITextControl
J#
/** @attribute ControlValuePropertyAttribute("Text") */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class Label extends WebControl implements ITextControl
JScript
public class Label extends WebControl implements ITextControl
ASP.NET
<asp:Label />

使用 Label 控件在网页的设置位置上显示文本。不像静态文本,可以通过 Text 属性自定义显示文本。

也可以使用 LiteralPlaceHolder 控件在 Web 窗体页上显示文本。但与 Label 控件不同的是,这些控件不会呈现任何附加标记。

安全说明:

此控件可用于显示用户输入,这可能会导致安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包括脚本或 HTML 元素。有关更多信息,请参见脚本侵入概述

辅助功能

默认情况下,为此控件呈现的标记可能不符合辅助功能标准,例如 Web 内容辅助功能准则 1.0 (WCAG) 优先级 1 准则。有关此控件的辅助功能支持的详细信息,请参见 ASP.NET 控件和辅助功能

TopicLocation
如何:以编程方式向 ASP.NET 网页添加控件生成 ASP .NET Web 应用程序
如何:以编程方式向 ASP.NET 网页添加控件在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:向 Web 窗体页添加 Label Web 服务器控件生成 ASP .NET Web 应用程序
如何:向 Web 窗体页添加 Label Web 服务器控件 (Visual Studio)在 Visual Studio 中构建 ASP .NET Web 应用程序
如何:向 Web 窗体页添加 Label Web 服务器控件 (Visual Studio)在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:在 Calendar Web 服务器控件中自定义个别日生成 ASP .NET Web 应用程序
如何:在 Calendar Web 服务器控件中自定义个别日在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:在 DataList Web 服务器控件中动态创建模板生成 ASP .NET Web 应用程序
如何:在 DataList Web 服务器控件中动态创建模板在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:将 Label Web 服务器控件用作标题生成 ASP .NET Web 应用程序
如何:将 Label Web 服务器控件用作标题在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:为 Web 服务器控件创建基本控件设计器创作 ASP.NET 控件
演练:为 Web 服务器控件创建基本控件设计器在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:使用主题自定义网站在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:使用主题自定义网站使用 Visual Web Developer 生成应用程序
演练:创建具有辅助功能的 Web 应用程序在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:创建具有辅助功能的 Web 应用程序使用 Visual Web Developer 生成应用程序
演练:到自定义业务对象的数据绑定在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:到自定义业务对象的数据绑定在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中使用级联样式表样式在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页使用 Visual Web Developer 生成应用程序
演练:在 Visual Web Developer 中创建基本网页在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建基本网页在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中通过代码分离创建基本网页在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中通过代码分离创建基本网页使用 Visual Web Developer 生成应用程序
演练:验证 Web 窗体页中的用户输入在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:验证 Web 窗体页中的用户输入使用 Visual Web Developer 生成应用程序

下面的示例说明如何在网页上创建 Label 控件。

说明:

下面的代码示例使用单文件代码模型,如果将它直接复制到代码隐藏文件中,可能不能正常工作。此代码示例必须被复制到具有 .aspx 扩展名的空文本文件中。有关 ASP.NET 网页代码模型的更多信息,请参见 ASP.NET 网页代码模型

安全说明:

此示例有一个接受用户输入的文本框,这是一个潜在的安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包括脚本或 HTML 元素。有关更多信息,请参见脚本侵入概述

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
    <title>Label Example</title>
<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>

C#
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head>
    <title>Label Example</title>
<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>


此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5、3.0、2.0、1.1、1.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker