Control.CreateControlCollection 메서드

정의

서버 컨트롤의 자식 컨트롤(리터럴 및 서버)을 보유할 새 ControlCollection 개체를 만듭니다.Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control.

protected:
 virtual System::Web::UI::ControlCollection ^ CreateControlCollection();
protected virtual System.Web.UI.ControlCollection CreateControlCollection ();
abstract member CreateControlCollection : unit -> System.Web.UI.ControlCollection
override this.CreateControlCollection : unit -> System.Web.UI.ControlCollection
Protected Overridable Function CreateControlCollection () As ControlCollection

반환

현재 서버 컨트롤의 자식 서버 컨트롤을 보유할 ControlCollection 개체입니다.A ControlCollection object to contain the current server control's child server controls.

예제

다음 코드 예제에서는 CreateControlCollection 메서드를 재정의 하 여 ControlCollection 클래스에서 상속 되는 CustomControlCollection 클래스의 인스턴스를 만듭니다.The following code example overrides the CreateControlCollection method to create an instance of a CustomControlCollection class, which inherits from the ControlCollection class.

// Override the CreateControlCollection method to 
// write to the Trace object when tracing is enabled
// for the page or application in which this control
// is included.   
protected override ControlCollection CreateControlCollection()
{
    return new CustomControlCollection(this);
}
' Override the CreateControlCollection method to 
' write to the Trace object when tracing is enabled
' for the page or application in which this control
' is included.   
Protected Overrides Function CreateControlCollection() As ControlCollection
    Return New CustomControlCollection(Me)
End Function

다음 코드 예제에서는 CreateChildControls 메서드의 사용자 지정 서버 컨트롤 재정의에 CreateControlCollection 메서드를 사용 합니다.The following code example uses the CreateControlCollection method in a custom server control override of the CreateChildControls method. 새 컬렉션을 만든 다음 두 개의 자식 컨트롤인 firstControlsecondControl채웁니다.The new collection is created, and then populated with two child controls, firstControl and secondControl.


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;
}

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


설명

ControlCollection 클래스에서 파생 된 컬렉션 개체를 만든 경우 사용자 지정 서버 컨트롤에서이 메서드를 재정의 합니다.Override this method in a custom server control if you have created a collection object that is derived from the ControlCollection class. 그런 다음이 메서드의 재정의에서 해당 컬렉션 클래스를 인스턴스화할 수 있습니다.You can then instantiate that collection class in the override of this method.

적용 대상

추가 정보