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