IAttributeAccessorとは? わかりやすく解説

IAttributeAccessor インターフェイス

サーバー コントロール開始タグ宣言され任意の属性プログラムによってアクセスするために、ASP.NET サーバー コントロール使用されるメソッド定義します

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Interface IAttributeAccessor
Dim instance As IAttributeAccessor
public interface IAttributeAccessor
public interface class IAttributeAccessor
public interface IAttributeAccessor
public interface IAttributeAccessor
解説解説

.NET Framework では、WebControl、HtmlControl、ListItem の各クラスから継承するカスタム サーバー コントロール作成する場合、これらの各クラスIAttributeAccessor インターフェイス実装しているため、プログラムによる属性へのアクセス自動的に有効になります

これらのクラスいずれからも継承しないカスタム サーバー コントロール作成しコントロール厳密に指定されプロパティ対応していない属性プログラムによってアクセスできるようにする場合は、必ず 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.
Imports System
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 'SetAttribute
   
   ' 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 'Render
 End Class 'MyTextBox
End Namespace 'AttributeAccessor
// 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 + ">");
      }
   }
}
package AttributeAccessor;

// 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.

import System.*;
import System.Web.UI.*;

public class MyTextBox extends Control implements
 IAttributeAccessor
{
    // Declare the Width property.
    /** @property 
     */
    public String get_Width()
    {
        return (String)(this.get_ViewState().get_Item("Width"));
    } //get_Width

    /** @property 
     */
    public void set_Width(String value)
    {
        this.get_ViewState().set_Item("Width", value);
    } //set_Width

    // Declare the Text property.
    /** @property 
     */
    public String get_Text()
    {
        return (String)(this.get_ViewState().get_Item("Text"));
    } //get_Text

    /** @property 
     */
    public void set_Text(String value)
    {
        this.get_ViewState().set_Item("Text", value);
    } //set_Text

    // 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)
    {
        this.get_ViewState().set_Item(name, value1);
    } //SetAttribute

    // 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)(this.get_ViewState().get_Item(name));
    } //GetAttribute

    protected void Render(HtmlTextWriter output)
    {
        output.Write("<input type=text id= " + this.get_UniqueID());
        output.Write(" Value='" + this.get_Text());
        output.Write("' Size=" + this.get_Width() +
 ">");
    } //Render
} //MyTextBox
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IAttributeAccessor メンバ
System.Web.UI 名前空間
HtmlControl
WebControl

IAttributeAccessor メソッド


パブリック メソッドパブリック メソッド

参照参照

関連項目

IAttributeAccessor インターフェイス
System.Web.UI 名前空間
HtmlControl
WebControl

IAttributeAccessor メンバ




英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IAttributeAccessor」の関連用語

IAttributeAccessorのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IAttributeAccessorのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS