IWebEditable.CreateEditorParts 方法

定義

傳回與伺服器控制項相關聯之自訂 EditorPart 控制項的集合,該伺服器控制項會實作 IWebEditable 介面。

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 控制項的集合。

範例

下列程式碼範例示範自訂 WebPart 控制項中 方法的 CreateEditorParts 覆寫。 在類別概觀主題的 IWebEditable 範例一節中找到執行範例所需的完整原始程式碼。

程式碼範例包含 介面的 IWebEditable 兩個成員。 請注意,方法的 CreateEditorParts 覆寫會 ArrayList 建立 以收集一或多個自訂 EditorPart 控制項,然後使用清單來建立 EditorPartCollection 物件。

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 可讓您建立與自訂控制項、 WebPart 控制項或使用者控制項相關聯的所有自訂 EditorPart 控制項集合,並將其傳回為 EditorPartCollection 物件。 每當伺服器控制項進入編輯模式時,控制項 WebPartManager 會取得集合,並建立所有 EditorPart 控制項的實例。

您通常會藉由覆寫其 CreateEditorParts 方法,在自訂 WebPart 控制項中實作此方法。 在 方法中,您會建立想要與控制項產生關聯的自訂 EditorPart 控制項實例、將它們新增至 EditorPartCollection 物件,然後傳回該物件。 然後,控制項的 EditorPart 集合會指派給 EditorParts 區域的 屬性 EditorZoneBase

注意

EditorPart 方法實作中新增至控制項集合 EditorPart 的任何 CreateEditorParts ,都必須有指派給其 ID 屬性的值,否則當集合指派給 EditorParts 屬性時,將會擲回例外狀況。

給實施者的注意事項

EditorPartCollection方法 CreateEditorParts() 傳回的物件是唯讀的,而且沒有可存取的方法可將個別控制項加入其中。 不過,在 方法的覆寫或實作中,您可以建立另一種 ICollection 物件,例如 ArrayList ,以包含所有自訂 EditorPart 控制項,並在建立新 EditorPartCollection 物件時將其傳遞至建構函式。 如需程式碼範例,請參閱範例一節。

適用於

另請參閱