Control.CreateControlCollection Yöntem

Tanım

Sunucu denetiminin alt denetimlerini (hem değişmez değer hem de sunucu) tutmak için yeni ControlCollection bir nesne oluşturur.

C#
protected virtual System.Web.UI.ControlCollection CreateControlCollection ();

Döndürülenler

ControlCollection

ControlCollection Geçerli sunucu denetiminin alt sunucu denetimlerini içeren bir nesne.

Örnekler

Aşağıdaki kod örneği, sınıfından CreateControlCollection devralan ControlCollection bir CustomControlCollection sınıfın örneğini oluşturmak için yöntemini geçersiz kılar.

C#
// 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);
}

Aşağıdaki kod örneği, yönteminin CreateControlCollection özel bir sunucu denetimi geçersiz kılmasında CreateChildControls yöntemini kullanır. Yeni koleksiyon oluşturulur ve ardından ve iki alt denetimle firstControl secondControldoldurulur.

C#

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

Açıklamalar

sınıfından türetilen bir koleksiyon nesnesi oluşturduysanız, özel bir sunucu denetiminde ControlCollection bu yöntemi geçersiz kılın. Daha sonra bu yöntemin geçersiz kılmasında bu koleksiyon sınıfının örneğini oluşturabilirsiniz.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

Ayrıca bkz.