更新 : 2007 年 11 月
Web ページにテキストを表示するラベル コントロールを表します。
<ControlValuePropertyAttribute("Text")> _ <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Class Label _ Inherits WebControl _ Implements ITextControl
Dim instance As Label
[ControlValuePropertyAttribute("Text")] [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class Label : WebControl, ITextControl
[ControlValuePropertyAttribute(L"Text")] [AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class Label : public WebControl, ITextControl
/** @attribute ControlValuePropertyAttribute("Text") */ /** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */ /** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */ public class Label extends WebControl implements ITextControl
public class Label extends WebControl implements ITextControl
<asp:Label />
Label コントロールを使用して、ページの設定位置にテキストを表示します。静的テキストとは異なり、Text プロパティによりテキストの表示をカスタマイズできます。
Literal コントロールと PlaceHolder コントロールを使用して、Web フォーム ページにテキストを表示することもできます。ただし、Label コントロールとは異なり、これらのコントロールは、追加タグは表示しません。
このコントロールは、ユーザー入力を表示する際に使用できます。これにより、セキュリティが脆弱になる可能性があります。既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。詳細については、「スクリプトによる攻略の概要」を参照してください。
このコントロールに既定でレンダリングされるマークアップは、Web Content Accessibility Guidelines (WCAG) 1.0 の優先度 1 ガイドラインなどのユーザー補助に関する標準に適合しない可能性があります。このコントロールのユーザー補助サポートの詳細については、「ASP.NET コントロールとユーザー補助」を参照してください。
Web ページに Label コントロールを作成する方法を次の例に示します。
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。ASP.NET Web ページのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。
この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。詳細については、「スクリプトによる攻略の概要」を参照してください。
<%@ 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>
<%@ 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>
(ホスト環境での動作に必要なアクセス許可)要求値 : LinkDemand; アクセス許可値 : Minimal。
(ホスト環境での動作に必要なアクセス許可)要求値 : InheritanceDemand; アクセス許可値 : Minimal。
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