Rediger

Del via


IWebEditable.CreateEditorParts Method

Definition

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

public:
 System::Web::UI::WebControls::WebParts::EditorPartCollection ^ CreateEditorParts();
public System.Web.UI.WebControls.WebParts.EditorPartCollection CreateEditorParts ();
abstract member CreateEditorParts : unit -> System.Web.UI.WebControls.WebParts.EditorPartCollection
Public Function CreateEditorParts () As EditorPartCollection

Returns

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

Examples

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";
  editorArray.Add(edPart);
  EditorPartCollection editorParts = 
    new EditorPartCollection(editorArray);
  return editorParts;
}

public override object WebBrowsableObject
{
  get { return this; }
}
Public Overrides Function CreateEditorParts() _
                            As EditorPartCollection
  Dim editorArray As New ArrayList()
  Dim edPart as New TextDisplayEditorPart()
  edPart.ID = Me.ID & "_editorPart1"
  editorArray.Add(edPart)
  Dim editorParts As New EditorPartCollection(editorArray)
  Return editorParts

End Function

Public Overrides ReadOnly Property WebBrowsableObject() _
                                    As Object
  Get
    Return Me
  End Get
End Property

Remarks

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.

Note

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.

Applies to

See also