EmptyControlCollection 類別

定義

為永遠都是空的 ControlCollection 集合提供標準支援。

public ref class EmptyControlCollection : System::Web::UI::ControlCollection
public class EmptyControlCollection : System.Web.UI.ControlCollection
type EmptyControlCollection = class
    inherit ControlCollection
Public Class EmptyControlCollection
Inherits ControlCollection
繼承
EmptyControlCollection

範例


/* 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.vb.

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

備註

當您想要定義不允許子控制項的自訂控制項時,會使用此類別。

建構函式

EmptyControlCollection(Control)

初始化 EmptyControlCollection 類別的新執行個體。

屬性

Count

取得指定 ASP.NET 伺服器控制項的 ControlCollection 物件中的伺服器控制項數目。

(繼承來源 ControlCollection)
IsReadOnly

取得值,這個值表示 ControlCollection 物件是否唯讀。

(繼承來源 ControlCollection)
IsSynchronized

取得值,該值指出是否同步處理 ControlCollection 物件。

(繼承來源 ControlCollection)
Item[Int32]

取得在 ControlCollection 物件中指定索引位置之伺服器控制項的參考。

(繼承來源 ControlCollection)
Owner

取得 ControlCollection 物件所屬的 ASP.NET 伺服器控制項。

(繼承來源 ControlCollection)
SyncRoot

取得可用來對控制項集合進行同步 (Synchronize) 存取的物件。

(繼承來源 ControlCollection)

方法

Add(Control)

拒絕將指定的 Control 物件加入到集合中。

AddAt(Int32, Control)

拒絕在指定的索引位置,將指定的 Control 物件加入集合。

Clear()

從目前伺服器控制項的 ControlCollection 物件中移除所有控制項。

(繼承來源 ControlCollection)
Contains(Control)

判斷指定伺服器控制項是否在伺服器控制項的 ControlCollection 物件之中。

(繼承來源 ControlCollection)
CopyTo(Array, Int32)

ControlCollection 中的指定索引位置開始,複製儲存於 Array 物件的子控制項至 Array 物件。

(繼承來源 ControlCollection)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

擷取可逐一查看 ControlCollection 物件的列舉值。

(繼承來源 ControlCollection)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IndexOf(Control)

擷取集合中指定 Control 物件的索引。

(繼承來源 ControlCollection)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Remove(Control)

從父伺服器控制項的 ControlCollection 物件移除指定伺服器控制項。

(繼承來源 ControlCollection)
RemoveAt(Int32)

在指定索引位置,從 ControlCollection 物件移除子控制項。

(繼承來源 ControlCollection)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於