次の方法で共有


HtmlControl.Attributes プロパティ

ASP.NET ページ内にある、サーバー コントロール タグで表現されるすべての属性名/値ペアのコレクションを取得します。

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

構文

'宣言
Public ReadOnly Property Attributes As AttributeCollection
'使用
Dim instance As HtmlControl
Dim value As AttributeCollection

value = instance.Attributes
public AttributeCollection Attributes { get; }
public:
property AttributeCollection^ Attributes {
    AttributeCollection^ get ();
}
/** @property */
public AttributeCollection get_Attributes ()
public function get Attributes () : AttributeCollection
適用できません。

プロパティ値

Web ページ内にあるサーバー コントロール タグで表現されるすべての属性名と値のペアが格納されている System.Web.UI.AttributeCollection オブジェクト。

解説

このプロパティを使用して、HTML サーバー コントロールの属性にプログラムによってアクセスします。すべての HTML サーバー コントロールは、その属性を Control.ViewState プロパティに格納します。

.NET Framework では、HTML 属性は、その属性が属している HTML サーバー コントロールのプロパティのように扱われます。

属性のコレクションの詳細については、System.Web.UI.AttributeCollection クラスのトピックを参照してください。

トピック 場所
方法 : ASP.NET Web ページのコントロールの HTML 属性を設定する Visual Studio ASP .NET での Web アプリケーションの作成
方法 : ASP.NET Web ページのコントロールの HTML 属性を設定する Visual Studio ASP .NET での Web アプリケーションの作成
方法 : ASP.NET Web ページのコントロールの HTML 属性を設定する ASP .NET Web アプリケーションの作成

使用例

Attributes プロパティを使用して、HtmlSelect コントロールの属性を確認する方法を次のコード例に示します。

<%@ 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" >

<script language="VB" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
        Message.InnerHtml = "<h4>" & "The select box's attributes collection contains:" & "</h4>"
        
        Dim keys As IEnumerator = Select1.Attributes.Keys.GetEnumerator()
        
        While keys.MoveNext()
            
            Dim key As String = CType(keys.Current, String)
            Message.InnerHtml &= key & "=" & Select1.Attributes(key) & "<br />"
        End While 
    End Sub 'Page_Load

</script>

<head runat="server">
    <title>" & "The select box's attributes collection contains:" & "</title>
</head>
<body>
<form id="Form1" runat="server">

   <h3>HtmlControl Attribute Collection Example</h3>

   Make a selection:

   <select id="Select1" 
           style="font: 12pt verdana;
                 background-color:yellow;
                 color:red;" 
           runat="server">

      <option>Item 1</option>
      <option>Item 2</option>
      <option>Item 3</option>

   </select>

   <br />

   <span id="Message" enableviewstate="false" runat="server" />
   
</form>
</body>
</html>
   
<%@ 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" >

<script language="C#" runat="server">
   void Page_Load(Object sender, EventArgs e) 
   {
      Message.InnerHtml = "<h4>The select box's attributes collection contains:</h4>";
     
      IEnumerator keys = Select.Attributes.Keys.GetEnumerator();

      while (keys.MoveNext()) 
      {

         String key = (String)keys.Current;
         Message.InnerHtml += key + "=" + Select.Attributes[key] + "<br />";

      }
   }

</script>

<head runat="server">
    <title>The select box's attributes collection contains:</title>
</head>
<body>
<form id="Form1" runat="server">

   <h3>HtmlControl Attribute Collection Example</h3>

   Make a selection:

   <select id="Select" 
           style="font: 12pt verdana;
                 background-color:yellow;
                 color:red;" 
           runat="server">

      <option>Item 1</option>
      <option>Item 2</option>
      <option>Item 3</option>

   </select>

   <br />

   <span id="Message" enableviewstate="false" runat="server" />
   
</form>
</body>
</html>
   
<%@ Page Language="JScript" 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" >

<script language="jscript" runat="server">
    function Page_Load(sender: Object, e: EventArgs){
        Message.InnerHtml = "<h4>The select box's attributes collection contains:</h4>"
        
        var keys: IEnumerator = Select1.Attributes.Keys.GetEnumerator()
        
        while(keys.MoveNext()){
            var key: String = String(keys.Current)
            Message.InnerHtml += key + "=" + Select1.Attributes(key) + "<br />"
        }
    }

</script>

<head runat="server">
    <title>The select box's attributes collection contains:</title>
</head>
<body>
<form id="Form1" runat="server">

   <h3>HtmlControl Attribute Collection Example</h3>

   Make a selection:

   <select id="Select1" 
           style="font: 12pt verdana;
                 background-color:yellow;
                 color:red;" 
           runat="server">

      <option>Item 1</option>
      <option>Item 2</option>
      <option>Item 3</option>

   </select>

   <br />

   <span id="Message" enableviewstate="false" runat="server" />
   
</form>
</body>
</html>
   

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

HtmlControl クラス
HtmlControl メンバ
System.Web.UI.HtmlControls 名前空間
System.Web.UI.AttributeCollection
Control.ViewState
HtmlSelect