WebControl.Attributes 속성

정의

컨트롤의 속성과 일치하지 않는 임의의 특성(렌더링하는 경우에만 해당)의 컬렉션을 가져옵니다.

public:
 property System::Web::UI::AttributeCollection ^ Attributes { System::Web::UI::AttributeCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.AttributeCollection Attributes { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Attributes : System.Web.UI.AttributeCollection
Public ReadOnly Property Attributes As AttributeCollection

속성 값

AttributeCollection

이름/값 쌍의 AttributeCollection입니다.

특성

예제

다음 예제를 하는 방법을 Attributes 의 속성을 WebControl JavaScript 실행에 사용할 수 있습니다 명령는 TextBox 컨트롤이 포커스를 잃을 합니다.

참고

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

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.


<%@ 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>Attributes Property of a Web Control</title>
<script language="C#" runat="server">
 
        void Page_Load(Object sender, EventArgs e) {
           TextBox1.Attributes["onblur"]="javascript:alert('Hello! Focus lost from text box!!');";    
        }
    </script>
 
 </head>
 <body>
    <h3>Attributes Property of a Web Control</h3>
 <form id="form1" runat="server">
 
    <asp:TextBox id="TextBox1" columns="54" 
     Text="Click here and then tap out of this text box" 
     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>Attributes Property of a Web Control</title>
<script language="VB" runat="server">
 
        Sub Page_Load(sender As Object, e As EventArgs)
            TextBox1.Attributes("onblur") = "javascript:alert('Hello! Focus lost from text box!!');"
        End Sub
    </script>
 
 </head>
 <body>
    <h3>Attributes Property of a Web Control</h3>
 <form id="form1" runat="server">
 
    <asp:TextBox id="TextBox1" columns="54" 
     Text="Click here and then tap out of this text box" 
     runat="server"/>  
 
 </form>
 </body>
 </html>

설명

Attributes 웹 서버 컨트롤의 여는 태그에 선언 된 모든 특성의 컬렉션을 포함 하는 컬렉션입니다. 이 옵션을 사용 하면 프로그래밍 방식으로 웹 서버 컨트롤과 연결 된 특성을 제어할 수 있습니다. 특성 컬렉션을 추가 하거나 컬렉션에서 특성을 제거할 수 있습니다.

참고

이 속성은 컨트롤의 여는 태그, 브라우저 설정에 관계 없이 컬렉션의 모든 특성으로 렌더링 됩니다. 일부 브라우저 렌더링 되는 모든 특성을 지원 합니다. 지원 되지 않는 특성은 일반적으로 브라우저에서 무시 됩니다.

참고

클라이언트 쪽 스크립트를 추가할 수 없습니다는 WebControl 를 사용 하 여 인스턴스를 Attributes 컬렉션입니다. 클라이언트 쪽 스크립트를 추가 하려면 사용 합니다 ClientScript 속성을를 Page 컨트롤입니다.

적용 대상

추가 정보