다음을 통해 공유


Label.Text 속성

정의

컨트롤의 Label 텍스트 내용을 가져오거나 설정합니다.

public:
 virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)]
public virtual string Text { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)>]
member this.Text : string with get, set
Public Overridable Property Text As String

속성 값

컨트롤의 텍스트 내용입니다. 기본값은 Empty입니다.

구현

특성

예제

다음 예제에서는 컨트롤의 Label 새 인스턴스를 만들고 해당 Text 속성을 설정하는 방법을 보여 줍니다.

메모

다음 코드 샘플에서는 단일 파일 코드 모델을 사용하며 코드 숨김 파일에 직접 복사한 경우 제대로 작동하지 않을 수 있습니다. 이 코드 샘플은 .aspx 확장이 있는 빈 텍스트 파일로 복사해야 합니다. Web Forms 코드 모델에 대한 자세한 내용은 ASP.NET Web Forms 페이지 코드 모델을 참조하세요.

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>Label Example</title>
<script language="C#" runat="server">
         void Button1_Click(Object Sender, EventArgs e) {
            Label l2 = new Label();
            l2.Text = "This is a new Label";
            l2.BorderStyle = BorderStyle.Solid;    
            Page.Controls.Add(l2);
         }
     </script>
 
 </head>
 <body>
     <h3>Label Example</h3>
     <form id="form1" runat="server">
 
         <asp:Button id="Button1" Text="Create and Show a Label" 
         OnClick="Button1_Click" Runat="server"/>
 
     </form>
 </body>
 </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 xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>Label Example</title>
<script language="VB" runat="server">
         Sub Button1_Click(Sender As Object, e As EventArgs)
            Dim l2 As New Label()
            l2.Text = "This is a new Label"
            l2.BorderStyle = BorderStyle.Solid
            Page.Controls.Add(l2)
         End Sub
     </script>
 
 </head>
 <body>
     <h3>Label Example</h3>
     <form id="form1" runat="server">
 
         <asp:Button id="Button1" Text="Create and Show a Label" 
         OnClick="Button1_Click" Runat="server"/>
 
     </form>
 </body>
 </html>

설명

Text 속성을 사용하여 컨트롤의 텍스트 내용을 지정하거나 확인합니다Label. 이 속성은 일반적으로 프로그래밍 방식으로 컨트롤에 표시 Label 되는 텍스트를 사용자 지정 하는 데 사용 합니다.

속성에는 HTML이 Text 포함될 수 있습니다. 이 경우 HTML은 변경되지 않은 상태로 브라우저에 전달됩니다. 여기서는 텍스트가 아닌 태그로 해석될 수 있습니다. 브라우저에서 HTML 태그를 일반 텍스트로 표시하려면 클래스 개요 예제와 같이 메서드를 사용할 HtmlEncode 수 있습니다. 컨트롤 대신 컨트롤을 LiteralLabel 사용하고 속성을 Encode.로 설정할 Mode 수도 있습니다.

메모

속성을 설정하면 컨트롤에 Text 포함된 다른 컨트롤이 지워지게 Label 됩니다.

중요합니다

이 컨트롤은 잠재적인 보안 위협인 사용자 입력을 표시하는 데 사용할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력에 스크립트 또는 HTML 요소가 포함되지 않는지 확인합니다. 자세한 내용은 스크립트 악용 개요를 참조하세요.

설정 시 이 속성의 값은 디자이너 도구를 사용하여 리소스 파일에 자동으로 저장할 수 있습니다. 자세한 내용은 세계화 및 지역화를 참조LocalizableAttribute하고 ASP.NET.

이 속성은 런타임에 개체가 ControlParameter 바인딩하는 기본 속성입니다. 자세한 내용은 필터링을 ControlValuePropertyAttributeControlParameter위해 데이터 원본 컨트롤과 함께 매개 변수 사용 및 참조하세요.

적용 대상