CreateEditorParts Method
Collapse the table of content
Expand the table of content

IWebEditable.CreateEditorParts Method

Note: This method is new in the .NET Framework version 2.0.

Returns a collection of custom EditorPart controls associated with a server control that implements the IWebEditable interface.

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

EditorPartCollection CreateEditorParts ()
EditorPartCollection CreateEditorParts ()
function CreateEditorParts () : EditorPartCollection

Return Value

An EditorPartCollection that contains the collection of custom EditorPart controls associated with a server control.

The CreateEditorParts method enables you to create a collection of all the custom EditorPart controls associated with your custom control, WebPart control, or user control, and return them as an EditorPartCollection object. The WebPartManager control takes the collection and creates instances of all the EditorPart controls whenever the server control enters edit mode.

Typically you implement this method in a custom WebPart control by overriding its CreateEditorParts method. In the method, you create instances of the custom EditorPart controls you want to associate with your controls, add them to an EditorPartCollection object, and then return that object. The collection of EditorPart controls is then assigned to the EditorParts property of the EditorZoneBase zone.


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.

Notes to Implementers The EditorPartCollection object that the CreateEditorParts method returns is read-only and has no accessible method to add individual controls to it. However, in your override or implementation of the method, you can create another kind of ICollection object, such as an ArrayList, to contain all the custom EditorPart controls, and pass it to the constructor when you create a new EditorPartCollection object. For a code example, see the Example section.

The following code example demonstrates an override of the CreateEditorParts method in a custom WebPart control. The complete source code required to run the sample is found in the Example section of the IWebEditable class overview topic.

The code example contains both members of the IWebEditable interface. Note that the override of the CreateEditorParts method creates an ArrayList to collect one or more custom EditorPart controls, and then uses the list to create the EditorPartCollection object.

public override EditorPartCollection CreateEditorParts()
  ArrayList editorArray = new ArrayList();
  TextDisplayEditorPart edPart = new TextDisplayEditorPart();
  edPart.ID = this.ID + "_editorPart1";
  EditorPartCollection editorParts = 
    new EditorPartCollection(editorArray);
  return editorParts;

public override object WebBrowsableObject
  get { return this; }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

© 2016 Microsoft