IAttributeAccessor 인터페이스

정의

ASP.NET 서버 컨트롤에서 서버 컨트롤의 여는 태그에 선언된 특성에 대해 프로그래밍 방식 액세스를 제공하는 데 사용되는 메서드를 정의합니다.

public interface class IAttributeAccessor
public interface IAttributeAccessor
type IAttributeAccessor = interface
Public Interface IAttributeAccessor
파생

예제

// The following class creates a custom ASP.NET server control that implements
// the IAttributeAccessor interface. It creates a MyTextBox class that contains
// Width and Text properties that get and set their values from view state.
// Pages that use this control create an instance of this control and set the
// Width property using the IAttributeAccessor.SetAttribute method. 
// The page then displays the values of the Text and Width properties 
// using the IAttributeAccessor.GetAttribute method.
// When compiled, this assembly is named MyAttributeAccessor.
using System;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;

namespace AttributeAccessor
{
   [AspNetHostingPermission(SecurityAction.Demand, 
      Level=AspNetHostingPermissionLevel.Minimal)]
   public sealed class MyTextBox : Control, IAttributeAccessor
   {
      // Declare the Width property.
      public String Width
      {
         get
         {
            return (String)ViewState["Width"];
         }
         set
         {
            ViewState["Width"] = value;
         }
      }

      // Declare the Text property.
      public String Text
      {
         get
         {
            return (String)ViewState["Text"];
         }
         set
         {
            ViewState["Text"] = value;
         }
      }
      // Implement the SetAttribute method for the control. When
      // this method is called from a page, the control's properties
      // are set to values defined in the page.
      public void SetAttribute(String name, String value1)
      {
         ViewState[name] = value1;
      }

      // Implement the GetAttribute method for the control. When
      // this method is called from a page, the values for the control's
      // properties can be displayed in the page.
      public String GetAttribute(String name)
      {
         return (String)ViewState[name];
      }

      protected override void Render(HtmlTextWriter output)
      {
         output.Write("<input type=text id= " + this.UniqueID);
         output.Write(" Value='" + this.Text);
         output.Write("' Size=" + this.Width + ">");
      }
   }
}
' The following class creates a custom ASP.NET server control that implements
' the IAttributeAccessor interface. It creates a MyTextBox class that contains
' Width and Text properties that get and set their values from view state.
' Pages that use this control create an instance of this control and set the
' Width property using the IAttributeAccessor.SetAttribute method. 
' The page then displays the values of the Text and Width properties 
' using the IAttributeAccessor.GetAttribute method.
' When compiled, this assembly is named MyAttributeAccessor.
Imports System.Web
Imports System.Web.UI
Imports System.Security.Permissions

Namespace AttributeAccessor

 <AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
 Public NotInheritable Class MyTextBox
   Inherits Control
   Implements IAttributeAccessor 

   ' Declare the Width property.   
   Public Property Width() As String
      Get
         Return CType(ViewState("Width"), String)
      End Get
      Set
         ViewState("Width") = value
      End Set
   End Property
   
   ' Declare the Text property.
   
   Public Property Text() As String
      Get
         Return CType(ViewState("Text"), String)
      End Get
      Set
         ViewState("Text") = value
      End Set
   End Property
   
   ' Implement the SetAttribute method for the control. When
   ' this method is called from a page, the control's properties
   ' are set to values defined in the page.
   Public Sub SetAttribute(name As String, value1 As String) Implements IAttributeAccessor.SetAttribute
      ViewState(name) = value1
   End Sub
   
   ' Implement the GetAttribute method for the control. When
   ' this method is called from a page, the values for the control's
   ' properties can be displayed in the page.
   Public Function GetAttribute(name As String) As String Implements IAttributeAccessor.GetAttribute
      Return CType(ViewState(name), String)
   End Function 'GetAttribute
   
   Protected Overrides Sub Render(output As HtmlTextWriter)
      output.Write(("<input type=text id= " + Me.UniqueID))
      output.Write((" Value='" + Me.Text))
      output.Write(("' Size=" + Me.Width + ">"))
   End Sub
 End Class
End Namespace 'AttributeAccessor

설명

상속 되는 사용자 지정 서버 컨트롤을 작성 하는 경우는 WebControl, HtmlControl, 또는 ListItem 클래스를.NET Framework 자동으로 프로그래밍 방식으로 액세스할 특성에 각 클래스 구현 하기 때문에 IAttributeAccessor 인터페이스입니다.

이러한 클래스 중 하나에서 상속 되지 않으며 컨트롤의 강력한 형식의 속성을 사용 하 여 일치 하지 않는 특성에 대 한 프로그래밍 방식의 액세스를 허용 하도록 계획 하는 사용자 지정 서버 컨트롤을 만든 경우 구현 해야 합니다 IAttributeAccessor 인터페이스입니다.

메서드

GetAttribute(String)

클래스에서 구현될 때, 서버 컨트롤에서 지정된 특성 속성을 검색합니다.

SetAttribute(String, String)

클래스에서 구현될 때, 특성을 지정하고 ASP.NET 서버 컨트롤에 할당할 해당 특성 값을 지정합니다.

적용 대상

추가 정보