Condividi tramite


ControlCollection(Control) Costruttore

Definizione

Inizializza una nuova istanza della ControlCollection classe per il controllo server padre specificato.

public:
 ControlCollection(System::Web::UI::Control ^ owner);
public ControlCollection(System.Web.UI.Control owner);
new System.Web.UI.ControlCollection : System.Web.UI.Control -> System.Web.UI.ControlCollection
Public Sub New (owner As Control)

Parametri

owner
Control

Controllo server ASP.NET per cui viene creata la raccolta di controlli.

Eccezioni

Si verifica se il owner parametro è null.

Esempio

L'esempio di codice seguente è una classe personalizzata ControlCollection che esegue l'override del costruttore per scrivere messaggi (che includono il nome della proprietà) nel log di Owner traccia quando viene creata un'istanza della raccolta. Per consentire il funzionamento di questo esempio, è necessario abilitare la traccia per la pagina o l'applicazione.

// Create a custom ControlCollection that writes
// information to the Trace log when an instance
// of the collection is created.
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class CustomControlCollection : ControlCollection
{
    private HttpContext context;

    public CustomControlCollection(Control owner)
        : base(owner)
    {

        HttpContext.Current.Trace.Write("The control collection is created.");
        // Display the Name of the control
        // that uses this collection when tracing is enabled.
        HttpContext.Current.Trace.Write("The owner is: " + this.Owner.ToString());
    }
}
' Create a custom ControlCollection that writes
' information to the Trace log when an instance
' of the collection is created.
<AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomControlCollection
    Inherits ControlCollection

    Private context As HttpContext

    Public Sub New(ByVal owner As Control)
        MyBase.New(owner)
        HttpContext.Current.Trace.Write("The control collection is created.")
        ' Display the Name of the control
        ' that uses this collection when tracing is enabled.
        HttpContext.Current.Trace.Write("The owner is: " _
      & Me.Owner.ToString())
    End Sub


End Class

Si applica a

Vedi anche