Control.CreateControlCollection 메서드

정의

서버 컨트롤의 자식 컨트롤(리터럴 및 서버)을 보유할 새 ControlCollection 개체를 만듭니다.

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

현재 서버 컨트롤의 자식 서버 컨트롤을 보유할 ControlCollection 개체입니다.

예제

다음 코드 예제에서는 클래스에서 상속 되는 클래스의 인스턴스를 CustomControlCollection 만드는 메서드를 ControlCollection 재정 CreateControlCollection 의 합니다.

// 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

다음 코드 예제에서는 메서드의 CreateControlCollection 사용자 지정 서버 컨트롤 재정의에서 메서드를 CreateChildControls 사용합니다. 새 컬렉션이 만들어지고 두 개의 자식 컨트롤 firstControl 로 채워집니다 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 합니다. 그런 다음, 이 메서드의 재정의에서 해당 컬렉션 클래스를 인스턴스화할 수 있습니다.

적용 대상

추가 정보