Control.CreateControlCollection Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Cria um novo ControlCollection objeto para armazenar os controlos filhos (tanto literais como de servidor) do controlo do servidor.
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
Devoluções
Um ControlCollection objeto para conter os controlos do servidor filho do controlo do servidor atual.
Exemplos
O seguinte exemplo de código sobrepõe o CreateControlCollection método para criar uma instância de uma CustomControlCollection classe, que herda da ControlCollection classe.
// 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
O seguinte exemplo de código utiliza o CreateControlCollection método numa sobreposição personalizada de controlo de servidor do CreateChildControls método. A nova coleção é criada e depois preenchida com dois controlos filhos, firstControl e 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
Observações
Substitua este método num controlo de servidor personalizado se tiver criado um objeto de coleção derivado da ControlCollection classe. Podes então instanciar essa classe de coleção no override deste método.