IWebEditable.CreateEditorParts 方法

定义

返回实现 EditorPart 接口的服务器控件的关联自定义 IWebEditable 控件的集合。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

返回

EditorPartCollection

EditorPartCollection,包含服务器控件的关联自定义 EditorPart 控件的集合。An EditorPartCollection that contains the collection of custom EditorPart controls associated with a server control.

示例

下面的代码示例演示如何重写 CreateEditorParts 自定义控件中的方法 WebPartThe following code example demonstrates an override of the CreateEditorParts method in a custom WebPart control. 运行示例所需的完整源代码位于类概述主题的 "示例" 部分 IWebEditableThe complete source code required to run the sample is found in the Example section of the IWebEditable class overview topic.

此代码示例包含接口的两个成员 IWebEditableThe code example contains both members of the IWebEditable interface. 请注意,方法的重写 CreateEditorParts 创建一个 ArrayList 来收集一个或多个自定义 EditorPart 控件,然后使用列表来创建 EditorPartCollection 对象。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

注解

CreateEditorParts使用方法可以创建 EditorPart 与自定义控件、控件或用户控件关联的所有自定义控件的集合 WebPart ,并将它们作为 EditorPartCollection 对象返回。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. WebPartManager EditorPart 每当服务器控件进入编辑模式时,控件都将获取集合并创建所有控件的实例。The WebPartManager control takes the collection and creates instances of all the EditorPart controls whenever the server control enters edit mode.

通常,通过重写自定义控件中的方法来实现此方法 WebPart CreateEditorPartsTypically you implement this method in a custom WebPart control by overriding its CreateEditorParts method. 在方法中,创建 EditorPart 要与控件关联的自定义控件的实例,将它们添加到 EditorPartCollection 对象,然后返回该对象。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. 然后,将 EditorPart 控件集合分配给 EditorParts 该区域的属性 EditorZoneBaseThe collection of EditorPart controls is then assigned to the EditorParts property of the EditorZoneBase zone.

备注

EditorPart在方法的实现中添加到控件集合的任何都 EditorPart 必须为 CreateEditorParts 其 ID 属性分配一个值,否则在将集合分配给属性时会引发异常 EditorPartsAny 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.

实施者说明

EditorPartCollectionCreateEditorParts() 方法返回的对象是只读的,并且没有可用于向其中添加单个控件的可访问方法。The EditorPartCollection object that the CreateEditorParts() method returns is read-only and has no accessible method to add individual controls to it. 但是,在方法的重写或实现中,可以创建另一种类型的 ICollection 对象(如 ArrayList )来包含所有自定义 EditorPart 控件,并在创建新对象时将其传递到构造函数 EditorPartCollectionHowever, 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.

适用于

另请参阅