EmptyControlCollectionとは? わかりやすく解説

EmptyControlCollection クラス

常に空の ControlCollection コレクションの標準サポートを提供します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class EmptyControlCollection
    Inherits ControlCollection
Dim instance As EmptyControlCollection
public class EmptyControlCollection : ControlCollection
public ref class EmptyControlCollection : public
 ControlCollection
public class EmptyControlCollection extends
 ControlCollection
public class EmptyControlCollection extends
 ControlCollection
解説解説
使用例使用例
' File name: emptyControlCollection.vb.

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections


Namespace CustomControls 

  Public Class MyVB_EmptyControl 
    Inherits Control
    
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
    Protected Overrides Function
 CreateControlCollection() As ControlCollection
    ' Function Name: CreateControlCollection.
    ' Denies the creation of any child control by creating an empty
 collection.
    ' Generates an exception if an attempt to create a child control
 is made.
      Return New EmptyControlCollection(Me)
    End Function 
    
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _  
    Protected Overrides Sub
 CreateChildControls()
    ' Sub Name: CreateChildControls.
    ' Populates the child control collection (Controls). 
    ' Note: This function will cause an exception because the control
 does not allow 
    ' child controls.
      Dim text As LiteralControl
      text = New LiteralControl("<h5>Composite
 Controls</h5>")
      Controls.Add(text)
    End Sub 
  End Class 

End Namespace 

/* File name: emptyControlCollection.cs. */

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace CustomControls
{

  // Defines a simple custom control.
  public class MyCS_EmptyControl : Control
  {
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name="FullTrust")] 
    protected override ControlCollection CreateControlCollection()
 
    /*
     * Function Name: CreateControlCollection.
     * Denies the creation of any child control by creating an empty collection.
     * Generates an exception if an attempt to create a child
 control is made.
     */
     {
       return new EmptyControlCollection(this);
     }
     
     [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name="FullTrust")] 
     protected override void CreateChildControls()
     /*
      * Function Name: CreateChildControls.
      * Populates the child control collection (Controls). 
      * Note: This function will cause an exception because the control does not
 allow 
      * child controls.
      */
      {
        // Create a literal control to contain the header and add it
 to the collection.
        LiteralControl text;
        text = new LiteralControl("<h5>Composite Controls</h5>");
        Controls.Add(text);
      }
   }

}
/* File name: emptyControlCollection.jsl. */
import System.*;
import System.Web.*;
import System.Web.UI.*;
import System.Web.UI.WebControls.*;
import System.Collections.*;

// Defines a simple custom control.
public class MyJSL_EmptyControl extends Control
{
//    /** @attribute System.Security.Permissions.PermissionSet(
//        System.Security.Permissions.SecurityAction.Demand, Name =
 "FullTrust")
//     */
    protected ControlCollection CreateControlCollection()
    /*
        Function Name: CreateControlCollection.
        Denies the creation of any child control by creating an empty
        collection.
        Generates an exception if an attempt to create a child
 control is
        made.
    */
    {        
        return new EmptyControlCollection(this);
    } //CreateControlCollection

    /** @attribute System.Security.Permissions.PermissionSet(
        System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")
     */
    protected void CreateChildControls()
    /*
        Function Name: CreateChildControls.
        Populates the child control collection (Controls). 
        Note: This function will cause an exception because the control
        does not allow child controls.
     */
    {        
        // Create a literal control to contain the header and add it
 to the
        // collection.
        LiteralControl text;
        text = new LiteralControl("<h5>Composite Controls</h5>");
        get_Controls().Add(text);
    } //CreateChildControls
} //MyJSL_EmptyControl
継承階層継承階層
System.Object
   System.Web.UI.ControlCollection
    System.Web.UI.EmptyControlCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
EmptyControlCollection メンバ
System.Web.UI 名前空間

EmptyControlCollection コンストラクタ

EmptyControlCollection クラスの新しいインスタンスを初期化します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim owner As Control

Dim instance As New EmptyControlCollection(owner)
public EmptyControlCollection (
    Control owner
)
public:
EmptyControlCollection (
    Control^ owner
)
public EmptyControlCollection (
    Control owner
)
public function EmptyControlCollection (
    owner : Control
)

パラメータ

owner

このコレクションを子コントロールのコレクションとして所有している Control。

使用例使用例

子コントロールを持つコントロールを設定しようとして例外が発生するコード例を次に示します。この例外は、コンテナ コントロールで子コントロールが許可されていないために発生します。実行可能ファイルを作成するために使用されるコマンド ラインを次に示します。

vbc /r:System.dll /r:System.Web.dll /t:library
       /out:myWebAppPath/bin/vb_myEmptyControlCollection.dll
       myEmptyControlCollection.vb
csc /t:library /out:myWebAppPath/bin/cs_myEmptyControlCollection.dll
    myEmptyControlCollection.cs
' File name: emptyControlCollection.vb.

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections


Namespace CustomControls 

  Public Class MyVB_EmptyControl 
    Inherits Control
    
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
    Protected Overrides Function
 CreateControlCollection() As ControlCollection
    ' Function Name: CreateControlCollection.
    ' Denies the creation of any child control by creating an empty
 collection.
    ' Generates an exception if an attempt to create a child control
 is made.
      Return New EmptyControlCollection(Me)
    End Function 
    
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _  
    Protected Overrides Sub
 CreateChildControls()
    ' Sub Name: CreateChildControls.
    ' Populates the child control collection (Controls). 
    ' Note: This function will cause an exception because the control
 does not allow 
    ' child controls.
      Dim text As LiteralControl
      text = New LiteralControl("<h5>Composite
 Controls</h5>")
      Controls.Add(text)
    End Sub 
  End Class 

End Namespace 

/* File name: emptyControlCollection.cs. */

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace CustomControls
{

  // Defines a simple custom control.
  public class MyCS_EmptyControl : Control
  {
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name="FullTrust")] 
    protected override ControlCollection CreateControlCollection()
 
    /*
     * Function Name: CreateControlCollection.
     * Denies the creation of any child control by creating an empty collection.
     * Generates an exception if an attempt to create a child
 control is made.
     */
     {
       return new EmptyControlCollection(this);
     }
     
     [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name="FullTrust")] 
     protected override void CreateChildControls()
     /*
      * Function Name: CreateChildControls.
      * Populates the child control collection (Controls). 
      * Note: This function will cause an exception because the control does not
 allow 
      * child controls.
      */
      {
        // Create a literal control to contain the header and add it
 to the collection.
        LiteralControl text;
        text = new LiteralControl("<h5>Composite Controls</h5>");
        Controls.Add(text);
      }
   }

}
/* File name: emptyControlCollection.jsl. */
import System.*;
import System.Web.*;
import System.Web.UI.*;
import System.Web.UI.WebControls.*;
import System.Collections.*;

// Defines a simple custom control.
public class MyJSL_EmptyControl extends Control
{
//    /** @attribute System.Security.Permissions.PermissionSet(
//        System.Security.Permissions.SecurityAction.Demand, Name =
 "FullTrust")
//     */
    protected ControlCollection CreateControlCollection()
    /*
        Function Name: CreateControlCollection.
        Denies the creation of any child control by creating an empty
        collection.
        Generates an exception if an attempt to create a child
 control is
        made.
    */
    {        
        return new EmptyControlCollection(this);
    } //CreateControlCollection

    /** @attribute System.Security.Permissions.PermissionSet(
        System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")
     */
    protected void CreateChildControls()
    /*
        Function Name: CreateChildControls.
        Populates the child control collection (Controls). 
        Note: This function will cause an exception because the control
        does not allow child controls.
     */
    {        
        // Create a literal control to contain the header and add it
 to the
        // collection.
        LiteralControl text;
        text = new LiteralControl("<h5>Composite Controls</h5>");
        get_Controls().Add(text);
    } //CreateChildControls
} //MyJSL_EmptyControl

上記で定義した空のカスタム コントロールを使用するコード例を次に示します。この例を実行すると、例外が発生します。Register ディレクティブに示される値には、前のコマンド ラインが反映されます。

<%@ Register TagPrefix="custom" Assembly="vb_myEmptyControlCollection"
 Namespace="CustomControls" %>
 <html>
  <body>
  <h1>Using an Empty Control</h1>
  <custom:MyVB_EmptyControl id="vbEmptyControlId"
 runat="server"/>
  </body>
 </html>
<%@ Register TagPrefix="custom" Assembly="cs_myEmptyControlCollection"
 Namespace="CustomControls" %>
 <html>
  <body>
  <h1>Using an Empty Control </h1>
  <custom:MyCS_EmptyControl id="csEmptyControlId" runat="server"/>
  </body>
 </html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
EmptyControlCollection クラス
EmptyControlCollection メンバ
System.Web.UI 名前空間

EmptyControlCollection プロパティ


パブリック プロパティパブリック プロパティ

( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ Count  指定された ASP.NET サーバー コントロールの ControlCollection オブジェクト内にあるサーバー コントロールの数を取得します。 ( ControlCollection から継承されます。)
パブリック プロパティ IsReadOnly  ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。 ( ControlCollection から継承されます。)
パブリック プロパティ IsSynchronized  ControlCollection オブジェクトの同期がとられているかどうかを示す値を取得します。 ( ControlCollection から継承されます。)
パブリック プロパティ Item  ControlCollection オブジェクトの指定されたインデックス位置にあるサーバー コントロールへの参照を取得します。 ( ControlCollection から継承されます。)
パブリック プロパティ SyncRoot  コントロールのコレクションへのアクセスを同期するために使用するオブジェクトを取得します。 ( ControlCollection から継承されます。)
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ Owner  ControlCollection オブジェクトが属する ASP.NET サーバー コントロールを取得します。 ( ControlCollection から継承されます。)
参照参照

関連項目

EmptyControlCollection クラス
System.Web.UI 名前空間

EmptyControlCollection メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add オーバーライドされます。 指定した Control オブジェクトのコレクションへの追加を拒否します。
パブリック メソッド AddAt オーバーライドされます。 指定した Control オブジェクトの、コレクション内の指定したインデックス位置への追加を拒否します。
パブリック メソッド Clear  現在のサーバー コントロールの ControlCollection オブジェクトからすべてのコントロールを削除します。 ( ControlCollection から継承されます。)
パブリック メソッド Contains  指定したサーバー コントロールが親サーバー コントロールの ControlCollection オブジェクト内にあるかどうかを確認します。 ( ControlCollection から継承されます。)
パブリック メソッド CopyTo  ControlCollection オブジェクトに格納されている子コントロールを、System.Array オブジェクトに、System.Array 内の指定したインデックス位置からコピーします。 ( ControlCollection から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator  ControlCollection オブジェクトを反復処理できる列挙子を取得します。 ( ControlCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IndexOf  コレクション内の指定した Control オブジェクトのインデックスを取得します。 ( ControlCollection から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Remove  親サーバー コントロールの ControlCollection オブジェクトから、指定したサーバー コントロールを削除します。 ( ControlCollection から継承されます。)
パブリック メソッド RemoveAt  ControlCollection オブジェクトから、指定したインデックス位置にある子コントロールを削除します。 ( ControlCollection から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

EmptyControlCollection クラス
System.Web.UI 名前空間

EmptyControlCollection メンバ

常に空の ControlCollection コレクションの標準サポートを提供します。

EmptyControlCollection データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド EmptyControlCollection EmptyControlCollection クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ Count  指定された ASP.NET サーバー コントロールの ControlCollection オブジェクト内にあるサーバー コントロールの数を取得します。(ControlCollection から継承されます。)
パブリック プロパティ IsReadOnly  ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。(ControlCollection から継承されます。)
パブリック プロパティ IsSynchronized  ControlCollection オブジェクトの同期がとられているかどうかを示す値を取得します。(ControlCollection から継承されます。)
パブリック プロパティ Item  ControlCollection オブジェクトの指定されたインデックス位置にあるサーバー コントロールへの参照を取得します。(ControlCollection から継承されます。)
パブリック プロパティ SyncRoot  コントロールのコレクションへのアクセスを同期するために使用するオブジェクトを取得します。(ControlCollection から継承されます。)
プロテクト プロパティプロテクト プロパティ
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Add オーバーライドされます。 指定した Control オブジェクトのコレクションへの追加を拒否します。
パブリック メソッド AddAt オーバーライドされます。 指定した Control オブジェクトの、コレクション内の指定したインデックス位置への追加を拒否します。
パブリック メソッド Clear  現在のサーバー コントロールの ControlCollection オブジェクトからすべてのコントロールを削除します。 (ControlCollection から継承されます。)
パブリック メソッド Contains  指定したサーバー コントロールが親サーバー コントロールの ControlCollection オブジェクト内にあるかどうかを確認します。 (ControlCollection から継承されます。)
パブリック メソッド CopyTo  ControlCollection オブジェクトに格納されている子コントロールを、System.Array オブジェクトに、System.Array 内の指定したインデックス位置からコピーします。 (ControlCollection から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator  ControlCollection オブジェクトを反復処理できる列挙子を取得します。 (ControlCollection から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IndexOf  コレクション内の指定した Control オブジェクトのインデックスを取得します。 (ControlCollection から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド Remove  親サーバー コントロールの ControlCollection オブジェクトから、指定したサーバー コントロールを削除します。 (ControlCollection から継承されます。)
パブリック メソッド RemoveAt  ControlCollection オブジェクトから、指定したインデックス位置にある子コントロールを削除します。 (ControlCollection から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

EmptyControlCollection クラス
System.Web.UI 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「EmptyControlCollection」の関連用語

EmptyControlCollectionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



EmptyControlCollectionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS