次の方法で共有


Control.Controls プロパティ

UI 階層構造の指定されたサーバー コントロールの子コントロールを表す ControlCollection オブジェクトを取得します。

Public Overridable ReadOnly Property Controls As ControlCollection
[C#]
public virtual ControlCollection Controls {get;}
[C++]
public: __property virtual ControlCollection* get_Controls();
[JScript]
public function get Controls() : ControlCollection;

プロパティ値

指定されたサーバー コントロールの子コントロールのコレクション。

解説

ASP.NET ページでは、サーバー コントロールの開始タグと終了タグの間でコントロールを宣言して追加すると、ASP.NET は自動的にそのコントロールを、格納する側のサーバー コントロールの ControlCollection に追加します。サーバーで処理されない HTML タグまたは文字列は LiteralControl オブジェクトとして扱われます。これらは、他のサーバー コントロールと同様にコレクションに追加されます。

Controls プロパティは、任意のサーバー コントロールの ControlCollection クラスにプログラムによりアクセスできるようにします。コントロールをコレクションに追加したり、コレクションから削除できます。また、コレクションのサーバー コントロールを反復処理できます。

使用例

Controls プロパティを通じてサーバー コントロールの ControlCollection オブジェクトに子コントロールを追加する方法を次の例に示します。

 
Controls.Add(New LiteralControl("<h3>Value: "))
  

[C#] 
Controls.Add(new LiteralControl("<h3>Value: "));

[C++] 
Controls->Add(new LiteralControl(S"<h3>Value: "));

[JScript] 
Controls.Add(new LiteralControl("<h3>Value: "));

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

Control クラス | Control メンバ | System.Web.UI 名前空間 | ControlCollection | CreateControlCollection | CreateChildControls