ControlCollection(Control) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化該類別的新實例 ControlCollection ,以啟用指定的父伺服器控制。
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)
參數
- owner
- Control
控制集合所用的 ASP.NET 伺服器控制。
例外狀況
當參數 owner 為 null時發生。
範例
以下程式碼範例是一個自訂 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