ControlCollection.Owner 屬性

定義

取得 ControlCollection 物件所屬的 ASP.NET 伺服器控制項。

protected:
 property System::Web::UI::Control ^ Owner { System::Web::UI::Control ^ get(); };
protected System.Web.UI.Control Owner { get; }
member this.Owner : System.Web.UI.Control
Protected ReadOnly Property Owner As Control

屬性值

Control 所屬的 ControlCollection

範例

下列程式碼範例是自訂 ControlCollection 類別,會覆寫 ControlCollection 方法,以在建立集合實例時,將屬性的名稱 Owner) 寫入訊息 (。 您必須啟用頁面或應用程式的追蹤,此範例才能運作。

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

適用於

另請參閱