Export (0) Print
Expand All

EditorZoneBase.EditorParts Property

Gets a collection of all the EditorPart controls contained in an EditorZoneBase zone.

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

[BrowsableAttribute(false)]
public EditorPartCollection EditorParts { get; }

Property Value

Type: System.Web.UI.WebControls.WebParts.EditorPartCollection
An EditorPartCollection that contains all the individual EditorPart controls in a zone.

ExceptionCondition
InvalidOperationException

An EditorPart being added to the collection does not have a value assigned to its ID property.

The EditorParts property provides a reference to a collection of all the EditorPart controls in the zone. It references both the EditorPart controls provided with the Web Parts control set, and any custom EditorPart controls that are added to the zone. Because the collection is read-only, developers who want to create custom EditorPart controls for general editing purposes and add them to the collection should override the CreateEditorParts method.

If you design custom EditorPart controls to edit a specific WebPart control, you should override the members of the IWebEditable interface--the CreateEditorParts method and the WebBrowsableObject property--in the WebPart control. The reason to override these members is to enable your WebPart control to create the custom EditorPart controls and add them to the EditorParts collection when your control is being edited, and to provide the editing controls with an object reference to the WebPart control they are editing. If you want to add a custom EditorPart control to edit a server control that does not inherit from the WebPart class, you must implement the IWebEditable interface in the class just as you would for a WebPart control.

NoteNote

Note that any EditorPart that is added to the collection of EditorPart controls in an implementation of the CreateEditorParts method must have a value assigned to its ID property, otherwise an exception will be thrown when the collection is assigned to the EditorParts property.

The following code example demonstrates how to access the EditorParts property programmatically. For the full code required to run the example, see the Example section of the EditorZoneBase class overview topic.

The first part of the code example demonstrates that the EditorParts property contains references to all the EditorPart controls that are referenced declaratively in the Web page.

<aspSample:MyEditorZone ID="EditorZone1" runat="server">
  <ApplyVerb Text="Apply Changes" />
  <CancelVerb Text="Cancel Changes" />
  <OKVerb Text="Finished" />
  <ZoneTemplate>
    <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
      runat="server" />
    <asp:LayoutEditorPart ID="LayoutEditorPart1" 
      runat="server" />
  </ZoneTemplate>
</aspSample:MyEditorZone>

The second part of the code example programmatically accesses the EditorParts property and lists the ID of each control in a Label control.

void Button3_Click(object sender, EventArgs e)
{
  Label1.Text = "<br />";
  foreach (EditorPart part in EditorZone1.EditorParts)
  {
    Label1.Text += part.ID + "<br />";
  }
}

When you load the page in a browser, you can click the Display EditorParts Collection button to list the IDs of all the EditorPart controls referenced in the EditorParts property.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft