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

備註

這個類別用於你想定義一個不允許子控制項的自訂控制項。

建構函式

名稱 Description
EmptyControlCollection(Control)

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

屬性

名稱 Description
Count

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

(繼承來源 ControlCollection)
IsReadOnly

會取得一個值,表示該物件是否 ControlCollection 為唯讀。

(繼承來源 ControlCollection)
IsSynchronized

會取得一個值,表示該物件是否 ControlCollection 同步。

(繼承來源 ControlCollection)
Item[Int32]

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

(繼承來源 ControlCollection)
Owner

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

(繼承來源 ControlCollection)
SyncRoot

取得一個物件,可以用來同步存取控制項集合。

(繼承來源 ControlCollection)

方法

名稱 Description
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)

擴充方法

名稱 Description
AsParallel(IEnumerable)

啟用查詢的平行處理。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

根據指定的型別篩選 IEnumerable 的專案。

適用於