ControlCollection(Control) 构造函数

定义

为指定的父服务器控件初始化 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

适用于

另请参阅