ControlCollection クラス
アセンブリ: System.Web (system.web.dll 内)


ControlCollection クラスの任意のプロパティおよびメソッドに、Control.Controls プロパティをとおしてアクセスできます。Control クラスはすべての ASP.NET サーバー コントロールの基本クラスであるため、すべてのサーバー コントロールは、このプロパティを継承します。
コレクションの詳細については、「コレクションとデータ構造体」を参照してください。

Control.CreateChildControls メソッドをオーバーライドして、2 つのコントロール (ChildControl という名前のカスタム クラスの 2 つのインスタンス) を作成するコード例を次に示します。これらのコントロールには、Message という名前の文字列プロパティが存在します。2 つのコントロールを、作成した後で ControlCollection に追加しています。このバージョンの Control.CreateChildControls を含むクラスにこれらのコントロールを追加するために、Add メソッドを各コントロールに対して呼び出しています。このコードではまた、作成したコントロールが不必要に再作成されることのないよう、ChildControlsCreated プロパティを true に設定します。
Protected Overrides Sub CreateChildControls() ' Creates a new ControlCollection. Me.CreateControlCollection() ' Create child controls. Dim firstControl As New ChildControl() firstControl.Message = "FirstChildControl" Dim secondControl As New ChildControl() secondControl.Message = "SecondChildControl" Controls.Add(firstControl) Controls.Add(secondControl) ' Prevent child controls from being created again. ChildControlsCreated = True End Sub 'CreateChildControls
protected override void CreateChildControls() { // Creates a new ControlCollection. this.CreateControlCollection(); // Create child controls. ChildControl firstControl = new ChildControl(); firstControl.Message = "FirstChildControl"; ChildControl secondControl = new ChildControl(); secondControl.Message = "SecondChildControl"; Controls.Add(firstControl); Controls.Add(secondControl); // Prevent child controls from being created again. ChildControlsCreated = true; }



Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlCollection コンストラクタ
アセンブリ: System.Web (system.web.dll 内)



次に示すのは、ControlCollection クラスのコンストラクタをオーバーライドするカスタム クラスのコード例です。このカスタム クラスでは、コレクションのインスタンスが作成されるとトレース ログにメッセージ (Owner プロパティの名前を含む) が書き込まれます。この例を使用するには、ページまたはアプリケーションでトレースの機能が有効になっている必要があります。
' Create a custom ControlCollection that writes ' information to the Trace log when an instance ' of the collection is created. <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ Public NotInheritable Class CustomControlCollection Inherits ControlCollection Private context As HttpContext Public Sub New(ByVal owner As Control) MyBase.New(owner) HttpContext.Current.Trace.Write("The control collection is created.") ' Display the Name of the control ' that uses this collection when tracing is enabled. HttpContext.Current.Trace.Write("The owner is: " _ & Me.Owner.ToString()) End Sub End Class
// Create a custom ControlCollection that writes // information to the Trace log when an instance // of the collection is created. [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)] public class CustomControlCollection : ControlCollection { private HttpContext context; public CustomControlCollection(Control owner) : base(owner) { HttpContext.Current.Trace.Write("The control collection is created."); // Display the Name of the control // that uses this collection when tracing is enabled. HttpContext.Current.Trace.Write("The owner is: " + this.Owner.ToString()); } }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlCollection プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | 指定された ASP.NET サーバー コントロールの ControlCollection オブジェクト内にあるサーバー コントロールの数を取得します。 |
![]() | IsReadOnly | ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。 |
![]() | IsSynchronized | ControlCollection オブジェクトの同期がとられているかどうかを示す値を取得します。 |
![]() | Item | ControlCollection オブジェクトの指定されたインデックス位置にあるサーバー コントロールへの参照を取得します。 |
![]() | SyncRoot | コントロールのコレクションへのアクセスを同期するために使用するオブジェクトを取得します。 |


ControlCollection メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | 指定した Control オブジェクトをコレクションに追加します。 |
![]() | AddAt | 指定したインデックス位置に、指定した Control オブジェクトを追加します。 |
![]() | Clear | 現在のサーバー コントロールの ControlCollection オブジェクトからすべてのコントロールを削除します。 |
![]() | Contains | 指定したサーバー コントロールが親サーバー コントロールの ControlCollection オブジェクト内にあるかどうかを確認します。 |
![]() | CopyTo | ControlCollection オブジェクトに格納されている子コントロールを、System.Array オブジェクトに、System.Array 内の指定したインデックス位置からコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | ControlCollection オブジェクトを反復処理できる列挙子を取得します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IndexOf | コレクション内の指定した Control オブジェクトのインデックスを取得します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Remove | 親サーバー コントロールの ControlCollection オブジェクトから、指定したサーバー コントロールを削除します。 |
![]() | RemoveAt | ControlCollection オブジェクトから、指定したインデックス位置にある子コントロールを削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

ControlCollection メンバ
ASP.NET サーバー コントロールが子コントロールのリストを維持できるようにする、コレクション コンテナを提供します。
ControlCollection データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Count | 指定された ASP.NET サーバー コントロールの ControlCollection オブジェクト内にあるサーバー コントロールの数を取得します。 |
![]() | IsReadOnly | ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。 |
![]() | IsSynchronized | ControlCollection オブジェクトの同期がとられているかどうかを示す値を取得します。 |
![]() | Item | ControlCollection オブジェクトの指定されたインデックス位置にあるサーバー コントロールへの参照を取得します。 |
![]() | SyncRoot | コントロールのコレクションへのアクセスを同期するために使用するオブジェクトを取得します。 |


名前 | 説明 | |
---|---|---|
![]() | Add | 指定した Control オブジェクトをコレクションに追加します。 |
![]() | AddAt | 指定したインデックス位置に、指定した Control オブジェクトを追加します。 |
![]() | Clear | 現在のサーバー コントロールの ControlCollection オブジェクトからすべてのコントロールを削除します。 |
![]() | Contains | 指定したサーバー コントロールが親サーバー コントロールの ControlCollection オブジェクト内にあるかどうかを確認します。 |
![]() | CopyTo | ControlCollection オブジェクトに格納されている子コントロールを、System.Array オブジェクトに、System.Array 内の指定したインデックス位置からコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | ControlCollection オブジェクトを反復処理できる列挙子を取得します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IndexOf | コレクション内の指定した Control オブジェクトのインデックスを取得します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Remove | 親サーバー コントロールの ControlCollection オブジェクトから、指定したサーバー コントロールを削除します。 |
![]() | RemoveAt | ControlCollection オブジェクトから、指定したインデックス位置にある子コントロールを削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- ControlCollectionのページへのリンク