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 である場合に発生します。

次のコード例は、コンストラクターをオーバーライドして、コレクションのインスタンスの作成時にトレース ログにメッセージ (プロパティのOwner名前を含む) を書き込むカスタム ControlCollection クラスです。 この例を機能させるには、ページまたはアプリケーションのトレースを有効にする必要があります。

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

適用対象

こちらもご覧ください