다음을 통해 공유


Literal.Text 속성

정의

컨트롤에 표시되는 캡션을 Literal 가져오거나 설정합니다.

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

속성 값

컨트롤에 표시되는 캡션입니다 Literal .

구현

특성

예제

다음 예제에서는 컨트롤에 표시 된 Literal 캡션을 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>Literal Example</title>
<script runat="server">

      void ButtonClick(Object sender, EventArgs e)
      {
         Literal1.Text="Welcome to ASP.NET!!";
      }

   </script>

</head>
<body>
   <form id="form1" runat="server">
      <h3>Literal Example</h3>

      <asp:Literal id="Literal1"
           Text="Hello World!!"
           runat="server"/>

      <br /><br />

      <asp:Button id="Button1"
           Text="Change Literal Text"
           OnClick="ButtonClick"
           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>Literal Example</title>
<script runat="server">

      Sub ButtonClick(sender As Object, e As EventArgs)
      
         Literal1.Text="Welcome to ASP.NET!!"
      
      End Sub

   </script>

</head>
<body>
   <form id="form1" runat="server">
      <h3>Literal Example</h3>

      <asp:Literal id="Literal1"
           Text="Hello World!!"
           runat="server"/>

      <br /><br />

      <asp:Button id="Button1"
           Text="Change Literal Text"
           OnClick="ButtonClick"
           runat="server"/>

   </form>
</body>
</html>

설명

컨트롤에 Text 표시되는 Literal 캡션을 지정하거나 확인하려면 이 속성을 사용합니다. 이를 통해 런타임에 캡션을 프로그래밍 방식으로 변경할 수 있습니다.

캡션은 이 속성에 값을 할당하는 방법에 따라 HTML로 디코딩됩니다. 컨트롤의 Literal 특성을 통해 값을 할당하면 값이 표시되기 전에 HTML 디코딩됩니다. 예를 들어 브라우저에서 <asp:Literal id="DisplayLiteral" Text="A&nbsp;B"/> "A B"로 렌더링됩니다. 그러나 이 속성을 프로그래밍 방식으로 설정하거나 컨트롤의 여는 태그와 닫는 태그 사이에 텍스트를 배치하면 캡션이 HTML 디코딩되지 않습니다. 예를 들어 <asp:Literal id="DisplayLiteral"> A&nbsp;B </asp:Literal> "A B"로 렌더링됩니다.

주의

이 컨트롤은 악의적인 클라이언트 스크립트를 포함할 수 있는 사용자 입력을 표시하는 데 사용할 수 있습니다. 애플리케이션에 표시하기 전에 클라이언트에서 전송된 모든 정보에서 실행 스크립트, SQL 문 또는 기타 코드를 확인합니다. ASP.NET 사용자 입력에서 스크립트 및 HTML을 차단하는 입력 요청 유효성 검사 기능을 제공합니다. 사용자 입력을 평가하기 위해 유효성 검사 서버 컨트롤도 제공됩니다. 자세한 내용은 유효성 검사 서버 컨트롤 구문을 참조하세요.

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

적용 대상

추가 정보