次の方法で共有


Control.CreateChildControls メソッド

コンポジション ベースの実装を使用するすべてのサーバー コントロールに、ポスト バックまたは表示のための準備として、格納する子コントロールを作成するように通知します。

Protected Overridable Sub CreateChildControls()
[C#]
protected virtual void CreateChildControls();
[C++]
protected: virtual void CreateChildControls();
[JScript]
protected function CreateChildControls();

解説

複合コントロールまたはテンプレート宣言されたサーバー コントロールを開発する場合は、このメソッドをオーバーライドする必要があります。詳細については、「 テンプレート コントロールの開発 」および「 複合コントロールの開発 」を参照してください。

一般的にオーバーライドされる Control クラス メソッドの概要については、「 ASP.NET サーバー コントロールのメソッド 」を参照してください。

使用例

CreatChildControls メソッドのオーバーライドされたバージョンの例を次に示します。この実装では、複合コントロールは、HTML を表示する 2 つのリテラル コントロールに囲まれた TextBox コントロールを表示します。

 
' Override CreateChildControls to create the control tree.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub CreateChildControls()
   
   ' Add a LiteralControl to the current ControlCollection.
   Me.Controls.Add(New LiteralControl("<h3>Value: "))
   
   
   ' Create a text box control, set the default Text property, 
   ' and add it to the ControlCollection.
   Dim box As New TextBox()
   box.Text = "0"
   Me.Controls.Add(box)
   
   Me.Controls.Add(New LiteralControl("</h3>"))
End Sub 'CreateChildControls

[C#] 
// Override CreateChildControls to create the control tree.
 [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
 protected override void CreateChildControls() {

     // Add a LiteralControl to the current ControlCollection.
     this.Controls.Add(new LiteralControl("<h3>Value: "));


     // Create a text box control, set the default Text property, 
     // and add it to the ControlCollection.
     TextBox box = new TextBox();
     box.Text = "0";
     this.Controls.Add(box);

     this.Controls.Add(new LiteralControl("</h3>"));
 }


[C++] 
// Override CreateChildControls to create the control tree.
protected:
[System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
void CreateChildControls() 
{
   // Add a LiteralControl to the current ControlCollection.
   this->Controls->Add(new LiteralControl(S"<h3>Value: "));

   // Create a text box control, set the default Text property,
   // and add it to the ControlCollection.
   TextBox* box = new TextBox();
   box->Text = S"0";
   this->Controls->Add(box);

   this->Controls->Add(new LiteralControl(S"</h3>"));
}

[JScript] 
// Override CreateChildControls to create the control tree.
 protected override function CreateChildControls() 
 {

     // Add a LiteralControl to the current ControlCollection.
     this.Controls.Add(new LiteralControl("<h3>Value: "));

     // Create a text box control, set the default Text property, 
     // and add it to the ControlCollection.
     var box : TextBox = new TextBox();
     box.Text = "0";
     this.Controls.Add(box);

     this.Controls.Add(new LiteralControl("</h3>"));
 }

必要条件

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

参照

Control クラス | Control メンバ | System.Web.UI 名前空間 | 複合コントロールの開発 | テンプレート コントロールの開発 | Controls | ControlCollection | ChildControlsCreated