EditorPartCollection Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Contains a collection of EditorPart controls used for editing the properties, layout, appearance, and behavior of WebPart controls. This class cannot be inherited.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)


Public NotInheritable Class EditorPartCollection
	Inherits ReadOnlyCollectionBase


Initializes an empty new instance of the EditorPartCollection class.

System_CAPS_pubmethodEditorPartCollection(EditorPartCollection, ICollection)

Initializes a new instance of the EditorPartCollection class by passing in an EditorPartCollection collection of EditorPart controls, and an ICollection collection of additional EditorPart controls.


Initializes a new instance of the EditorPartCollection class by passing in an ICollection collection of EditorPart controls.


Gets the number of elements contained in the ReadOnlyCollectionBase instance.(Inherited from ReadOnlyCollectionBase.)


Returns a specific member of the collection according to a unique identifier.


Returns a value that indicates whether a particular control is in the collection.

System_CAPS_pubmethodCopyTo(EditorPart(), Int32)

Copies the collection to an array of EditorPart controls.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Returns an enumerator that iterates through the ReadOnlyCollectionBase instance.(Inherited from ReadOnlyCollectionBase.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Returns the position of a particular member of the collection.


Returns a string that represents the current object.(Inherited from Object.)


References a static, read-only, empty instance of the collection.

System_CAPS_pubinterfaceSystem_CAPS_privmethodICollection.CopyTo(Array, Int32)

Copies the entire ReadOnlyCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.(Inherited from ReadOnlyCollectionBase.)


Gets a value indicating whether access to a ReadOnlyCollectionBase object is synchronized (thread safe).(Inherited from ReadOnlyCollectionBase.)


Gets an object that can be used to synchronize access to a ReadOnlyCollectionBase object.(Inherited from ReadOnlyCollectionBase.)


Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)


Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast(Of TResult)()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType(Of TResult)()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

The EditorPartCollection class is a read-only collection of EditorPart controls, typically used by an EditorZoneBase zone to track the set of EditorPart controls contained by the zone.

When a Web Parts page enters edit mode, and a user selects a control to edit, the editing process begins. The zone creates a new EditorPartCollection object consisting of the EditorPart controls contained by the zone. At various phases in the editing process, the zone accesses the EditorPartCollection object to save or retrieve property values between the EditorPart controls in the collection and the WebPart control currently being edited.

You can create an EditorPartCollection collection of controls for your own programmatic use if, for example, you need to perform some mass operation on a set of EditorPart controls. Even though the EditorPartCollection object is read-only, you can make programmatic changes to the properties of the underlying controls referenced in the collection.

The following code example demonstrates several uses of the EditorPartCollection class. There are four parts to this code example:

  • A user control that enables you to change display modes on a Web Parts page.

  • A class for a custom WebPart control named TextDisplayWebPart, which is referenced in the Web page and is edited by the EditorPart controls.

  • A Web page that references the TextDisplayWebPart control, contains an EditorZone control with several of the EditorPart controls from the Web Parts control set declared in the zone, and contains some event-driven code to create and manipulate an EditorPartCollection object.

  • An explanation of how the code example works when you load it in a browser.

The first part of this code example is the user control that enables users to change display modes on a Web page. For details about display modes and a description of the source code in this control, see Walkthrough: Changing Display Modes on a Web Parts Page.

<%@ control language="vb" classname="DisplayModeMenuVB"%>

<script runat="server">

' Use a field to reference the current WebPartManager.
Dim _manager As WebPartManager

Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) 
    AddHandler Page.InitComplete, AddressOf InitComplete

End Sub 

Sub InitComplete(ByVal sender As Object, ByVal e As System.EventArgs) 
    _manager = WebPartManager.GetCurrentWebPartManager(Page)

    Dim browseModeName As String = _

    ' Fill the dropdown with the names of supported display modes.
    Dim mode As WebPartDisplayMode
    For Each mode In  _manager.SupportedDisplayModes
        Dim modeName As String = mode.Name
        ' Make sure a mode is enabled before adding it.
        If mode.IsEnabled(_manager) Then
        Dim item As New ListItem(modeName, modeName)
        End If
    Next mode

End Sub 

' Change the page to the selected display mode.
  Sub DisplayModeDropdown_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    Dim selectedMode As String = DisplayModeDropdown.SelectedValue

    Dim mode As WebPartDisplayMode = _
    If Not (mode Is Nothing) Then
      _manager.DisplayMode = mode
    End If

  End Sub

Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
    DisplayModeDropdown.SelectedValue = _manager.DisplayMode.Name

End Sub 

  <asp:Panel ID="Panel1" runat="server" 
    Font-Names="Verdana, Arial, Sans Serif" >
  <asp:Label ID="Label1" runat="server" 
    Text="&nbsp;Display Mode" 
  <asp:DropDownList ID="DisplayModeDropdown" 
    OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />

The second part of the code example is the TextDisplayWebPart control. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Web Server Control.

Note that the control has a property named ContentText; this property holds the value that the user enters in the text box. This custom property can be edited when the control is in edit mode, along with the standard WebPart control properties.

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class TextDisplayWebPart
    Inherits WebPart
    Private _contentText As String = Nothing
    Private _fontStyle As String = Nothing
    Private input As TextBox
    Private DisplayContent As Label
    Private lineBreak As Literal

    <Personalizable(), WebBrowsable()> _
    Public Property ContentText() As String
        Return _contentText
      End Get
      Set(ByVal value As String)
        _contentText = value
      End Set
    End Property

    Protected Overrides Sub CreateChildControls()
      DisplayContent = New Label()
      DisplayContent.BackColor = Color.LightBlue
      DisplayContent.Text = Me.ContentText

      lineBreak = New Literal()
      lineBreak.Text = "<br />"

      input = New TextBox()
      Dim update As New Button()
      update.Text = "Set Label Content"
      AddHandler update.Click, AddressOf Me.submit_Click

    End Sub

    Private Sub submit_Click(ByVal sender As Object, _
                             ByVal e As EventArgs)
      ' Update the label string.
      If input.Text <> String.Empty Then
        _contentText = input.Text + "<br />"
        input.Text = String.Empty
        DisplayContent.Text = Me.ContentText
      End If

    End Sub

  End Class

End Namespace

The third part of the code example is the Web page. Notice that the <asp:editorzone> element for the page contains declarations for three EditorPart controls. Two of these controls become part of a custom EditorPartCollection object that is created when the Button1_Click method executes.

<%@ page language="vb" %>
<%@ register TagPrefix="uc1" 
  Src="DisplayModevb.ascx" %>
<%@ register tagprefix="aspSample" 
  Assembly="TextDisplayWebPartVB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)

    Dim list As New ArrayList(2)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New EditorPartCollection(list)
    Dim editor As EditorPart
    For Each editor In myParts
      editor.BackColor = System.Drawing.Color.LightBlue
      editor.Description = "My " + editor.DisplayTitle + " editor."
    Next editor

    ' Use the IndexOf property to locate an EditorPart control.
    Dim propertyGridPart As Integer = _
    myParts(propertyGridPart).ChromeType = PartChromeType.TitleOnly

    ' Use the Contains method to see if an EditorPart exists.
    If Not myParts.Contains(LayoutEditorPart1) Then
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow
    End If

    ' Use the CopyTo method to create an array of EditorParts.
    Dim partArray(2) As EditorPart
    partArray(0) = LayoutEditorPart1
    myParts.CopyTo(partArray, 1)
    Label1.Text = "<h3>EditorParts in Custom Array</h3>"
    Dim ePart As EditorPart
    For Each ePart In partArray
      Label1.Text += ePart.Title + "<br />"
    Next ePart

  End Sub

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
      Text Display WebPart with AppearanceEditorPart
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <uc1:DisplayModeMenu ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server">
            title = "Text Content WebPart" />          
      <asp:EditorZone ID="EditorZone1" runat="server">
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
            runat="server" />
          <asp:LayoutEditorPart ID="LayoutEditorPart1" 
            runat="server" />
          <asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" 
            runat="server" />
      <asp:Button ID="Button1" runat="server" 
        Text="Create EditorPartCollection" 
        OnClick="Button1_Click" />
      <asp:Label ID="Label1" runat="server" Text="" />

When you load the page in a browser, you can switch the page into edit mode by selecting Edit in the Display Mode drop-down list control. You can click the verbs menu (the downward arrow) in the title bar of the TextDisplayWebPart control, and click Edit to edit the control. When the editing user interface (UI) is visible, you can see all the EditorPart controls. You click the Create EditorPartCollection button to see the effects on the EditorPart controls that are created by the code that is manipulating the EditorPartCollection object. Also, notice that the PropertyGridEditorPart control allows you to edit the custom TextDisplayWebPart.ContentText property. This is possible because the property is marked with a WebBrowsable attribute in the source code for the control. If you update the property value in the editing UI, you must return the page to normal browse mode to see the effect of updating the TextDisplayWebPart.ContentText property.

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top