EmptyControlCollection 类

定义

对始终为空白的 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
继承
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 

注解

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

构造函数

EmptyControlCollection(Control)

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

属性

Count

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

(继承自 ControlCollection)
IsReadOnly

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

(继承自 ControlCollection)
IsSynchronized

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

(继承自 ControlCollection)
Item[Int32]

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

(继承自 ControlCollection)
Owner

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

(继承自 ControlCollection)
SyncRoot

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

(继承自 ControlCollection)

方法

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.

(继承自 ControlCollection)
Contains(Control)

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

(继承自 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.

(继承自 ControlCollection)
Equals(Object)

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

(继承自 Object)
GetEnumerator()

检索可以循环访问 ControlCollection 对象的枚举数。Retrieves an enumerator that can iterate through the ControlCollection object.

(继承自 ControlCollection)
GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
IndexOf(Control)

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

(继承自 ControlCollection)
MemberwiseClone()

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

(继承自 Object)
Remove(Control)

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

(继承自 ControlCollection)
RemoveAt(Int32)

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

(继承自 ControlCollection)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

扩展方法

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.

适用于