EmptyControlCollection Class

Definition

对始终为空白的 ControlCollection 集合提供标准支持。Provides standard support for a ControlCollection collection that is always empty.

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
Inheritance
EmptyControlCollection

Examples


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

Remarks

当要定义不允许使用子控件的自定义控件时, 可以使用此类。This class is used when you want to define a custom control that does not allow child controls.

Constructors

EmptyControlCollection(Control)

初始化 EmptyControlCollection 类的新实例。Initializes a new instance of the EmptyControlCollection class.

Properties

Count

为指定的 ASP.NET 服务器控件获取 ControlCollection 对象中的服务器控件数。Gets the number of server controls in the ControlCollection object for the specified ASP.NET server control.

(Inherited from ControlCollection)
IsReadOnly

获取一个值,该值指示 ControlCollection 对象是否为只读。Gets a value indicating whether the ControlCollection object is read-only.

(Inherited from ControlCollection)
IsSynchronized

获取一个值,该值指示是否同步 ControlCollection 对象。Gets a value indicating whether the ControlCollection object is synchronized.

(Inherited from ControlCollection)
Item[Int32]

获取对 ControlCollection 对象中指定索引位置的服务器控件的引用。Gets a reference to the server control at the specified index location in the ControlCollection object.

(Inherited from ControlCollection)
Owner

获取 ControlCollection 对象所属的 ASP.NET 服务器控件。Gets the ASP.NET server control to which the ControlCollection object belongs.

(Inherited from ControlCollection)
SyncRoot

获取可用于同步对控件集合的访问的对象。Gets an object that can be used to synchronize access to the collection of controls.

(Inherited from ControlCollection)

Methods

Add(Control)

拒绝将指定的 Control 对象添加到集合中。Denies the addition of the specified Control object to the collection.

AddAt(Int32, Control)

拒绝将指定的 Control 对象添加到集合中的指定索引位置。Denies the addition of the specified Control object to the collection, at the specified index position.

Clear()

从当前服务器控件的 ControlCollection 对象中移除所有控件。Removes all controls from the current server control's ControlCollection object.

(Inherited from ControlCollection)
Contains(Control)

确定指定的服务器控件是否在父服务器控件的 ControlCollection 对象中。Determines whether the specified server control is in the parent server control's ControlCollection object.

(Inherited from ControlCollection)
CopyTo(Array, Int32)

ControlCollection 中的指定索引位置开始,将 Array 对象中存储的子控件复制到 Array 对象。Copies the child controls stored in the ControlCollection object to an Array object, beginning at the specified index location in the Array.

(Inherited from ControlCollection)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

检索可遍历 ControlCollection 对象的枚举器。Retrieves an enumerator that can iterate through the ControlCollection object.

(Inherited from ControlCollection)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(Control)

检索集合中指定 Control 对象的索引。Retrieves the index of a specified Control object in the collection.

(Inherited from ControlCollection)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(Control)

从父服务器控件的 ControlCollection 对象中移除指定服务器控件。Removes the specified server control from the parent server control's ControlCollection object.

(Inherited from ControlCollection)
RemoveAt(Int32)

ControlCollection 对象中移除指定索引位置处的子控件。Removes a child control, at the specified index location, from the ControlCollection object.

(Inherited from ControlCollection)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Extension Methods

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Applies to