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

获取对象所属 ASP.NET 服务器控件 ControlCollection

(继承自 ControlCollection)
SyncRoot

获取一个对象,该对象可用于同步对控件集合的访问。

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

扩展方法

名称 说明
AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

适用于