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 Объект, содержащий дочерние элементы управления сервера текущего элемента управления.
Примеры
В следующем примере кода метод переопределяется CreateControlCollection для создания экземпляра CustomControlCollection класса, наследуемого ControlCollection от класса.
// 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 метода. Новая коллекция создается, а затем заполняется двумя дочерними элементами управления и firstControlsecondControl.
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 класса. Затем можно создать экземпляр этого класса коллекции в переопределении этого метода.