.NET Framework Class Library Label Class Represents a label control, which displays text on a Web page. Namespace:
System.Web.UI.WebControlsAssembly:
System.Web (in System.Web.dll)

Syntax
Visual Basic (Declaration)
<ControlValuePropertyAttribute("Text")> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Label _
Inherits WebControl _
Implements ITextControl
[ControlValuePropertyAttribute("Text")]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Label : WebControl, ITextControl
[ControlValuePropertyAttribute(L"Text")]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Label : public WebControl,
ITextControl
public class Label extends WebControl implements ITextControl

Remarks
Use the Label control to display text in a set location on the page.Unlike static text, you can customize the displayed text through the Text property. You can also use the Literal and PlaceHolder controls to display text on the Web Forms page.However, unlike the Label control, these controls do not render any additional tags. Security Note: |
|---|
This control can be used to display user input, which is a potential security threat.By default, ASP.NET Web pages validate that user input does not include script or HTML elements.For more information, see Script Exploits Overview. |
AccessibilityThe markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines.For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

Examples
The following example demonstrates how to create a Label control on a Web page. Note: |
|---|
The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file.This code sample must be copied into an empty text file that has an .aspx extension.For more information on the ASP.NET Web page code model, see ASP.NET Web Page Code Model. |
Security Note: |
|---|
This example has a text box that accepts user input, which is a potential security threat.By default, ASP.NET Web pages validate that user input does not include script or HTML elements.For more information, see Script Exploits Overview. |
<%@ Page Language= AutoEventWireup= %>
<!DOCTYPE html PUBLIC
>
<html xmlns= >
<head>
<title>Label Example</title>
<script language= runat=>
Button_Click(Sender Object, e EventArgs)
Label1.Text = Server.HtmlEncode(Text1.Text)
</script>
</head>
<body>
<form id= runat=>
<h3>Label Example</h3>
<asp:Label id=
Text=
runat=/>
<p>
<asp:TextBox id=
Text=
Width=
runat= />
<asp:Button id=
Text=
OnClick=
runat=/>
</p>
</form>
</body>
</html>
<%@ Page Language= AutoEventWireup= %>
<!DOCTYPE html PUBLIC "-
"http:
<html xmlns="http:
<head>
<title>Label Example</title>
<script language= runat=>
Button_Click(Object Sender, EventArgs e)
{
Label1.Text = Server.HtmlEncode(Text1.Text);
}
</script>
</head>
<body>
<form id= runat=>
<h3>Label Example</h3>
<asp:Label id=
Text=
runat=/>
<p>
<asp:TextBox id=
Text=
Width=
runat= />
<asp:Button id=
Text=
OnClick=
runat=/>
</p>
</form>
</body>
</html>

Permissions

Inheritance Hierarchy

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
.NET Framework Class Library Label Classe Representa um Controlarar de rótulo, que exibe texto em uma página da Web. Namespace:
System.Web.UI.WebControlsAssembly:
System.Web (em System.Web. dll)

Sintaxe
Visual Basic (Declaração)
<ControlValuePropertyAttribute("Text")> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Label _
Inherits WebControl _
Implements ITextControl
[ControlValuePropertyAttribute("Text")]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Label : WebControl, ITextControl
[ControlValuePropertyAttribute(L"Text")]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Label : public WebControl,
ITextControl
public class Label extends WebControl implements ITextControl

Comentários
Use the Label control to display text in a set location on the page.Unlike static text, you can customize the displayed text through the Text property. You can also use the Literal and PlaceHolder controls to display text on the Web Forms page.No entanto, diferentemente do controle Label, esses controles não processam as marcas adicionais. Observação de segurança: |
|---|
Este Controlarar pode ser usado para exibir a entrada do usuário, que é uma ameaça potencial à segurança.Por padrão, páginas Web ASP.NET validam se as entradas de usuário não incluem scripts ou elementos HTML.Para mais informações, acesse Visão Geral de Scripts Maliciosos. |
AcessibilidadeA marcação processada por padrão para este controle pode atendem aos padrões de acessibilidade, como as diretrizes Prioridade 1 Web conteúdo acessibilidade diretrizes 1.0 (WCAG) não.For details about accessibility support for this control, see Controles ASP.NET e acessibilidade.

Exemplos
The following example demonstrates how to create a Label control on a Web page. Observação: |
|---|
Exemplo de código a seguir usa o modelo de arquivo único código e pode não funcionar corretamente se copiado diretamente em um arquivo code-behind.Este exemplo de código deve ser copiado em um arquivo de texto vazia que possui uma extensão.aspx.For more information on the ASP.NET Web page code model, see Modelo de código de página Web do ASP.NET. |
Observação de segurança: |
|---|
Este exemplo tem uma caixa de texto que aceita entrada do usuário, que é uma ameaça potencial de segurança.Por padrão, páginas Web ASP.NET validam se as entradas de usuário não incluem scripts ou elementos HTML.Para mais informações, acesse Visão Geral de Scripts Maliciosos. |
<%@ Page Language= AutoEventWireup= %>
<!DOCTYPE html PUBLIC
>
<html xmlns= >
<head>
<title>Label Example</title>
<script language= runat=>
Button_Click(Sender Object, e EventArgs)
Label1.Text = Server.HtmlEncode(Text1.Text)
</script>
</head>
<body>
<form id= runat=>
<h3>Label Example</h3>
<asp:Label id=
Text=
runat=/>
<p>
<asp:TextBox id=
Text=
Width=
runat= />
<asp:Button id=
Text=
OnClick=
runat=/>
</p>
</form>
</body>
</html>
<%@ Page Language= AutoEventWireup= %>
<!DOCTYPE html PUBLIC "-
"http:
<html xmlns="http:
<head>
<title>Label Example</title>
<script language= runat=>
Button_Click(Object Sender, EventArgs e)
{
Label1.Text = Server.HtmlEncode(Text1.Text);
}
</script>
</head>
<body>
<form id= runat=>
<h3>Label Example</h3>
<asp:Label id=
Text=
runat=/>
<p>
<asp:TextBox id=
Text=
Width=
runat= />
<asp:Button id=
Text=
OnClick=
runat=/>
</p>
</form>
</body>
</html>

Permissões

Hierarquia de herança

Segurança de Segmentos
Quaisquer membros públicos estático ( compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.

Consulte também
ReferênciaOutros recursos
|