次の方法で共有


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

.NET Framework のセキュリティ

  • AspNetHostingPermission  (ホスト環境での動作に必要なアクセス許可)。要求値 : LinkDemand。アクセス許可値 : Minimal
  • AspNetHostingPermission  (ホスト環境での動作に必要なアクセス許可)。要求値 : InheritanceDemand。アクセス許可値 : Minimal

継承階層

System.Object
   System.Web.UI.ControlCollection
    System.Web.UI.EmptyControlCollection

スレッド セーフ

この型の public static (Visual Basicでは共有) メンバはすべて,スレッド セーフです。インスタンス メンバの場合は,スレッド セーフであるとは限りません。

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

EmptyControlCollection メンバ
System.Web.UI 名前空間