Search code examples
sharepointweb-parts

How to set EditorPart header in SharePoint WebParts?


I m trying to set the header for the custom Editor Part section. Any ideas how to do it?


Solution

  • EditorPart Class:

    public class YourCustomEditorPart:System.Web.UI.WebControls.WebParts.EditorPart{
       protected override void CreateChildControls() {
          this.Title = "Editor Part Title Here";
          ...
       }
    }
    

    Tell the web part that it should use this editor part, instead of the attributed properties.

    WebPart Class:

    public class YourWebPart:System.Web.UI.WebControls.WebParts.WebPart, IWebEditable {
    ...
    EditorPartCollection IWebEditable.CreateEditorParts() {
        // control the editorparts
        List<EditorPart> editors = new List<EditorPart>();
        YourCustomEditorPart editorPart = new YourCustomEditorPart();
        editorPart.ID = this.ID + "_editorPart";
        editors.Add(editorPart);
        return new EditorPartCollection(editors);
        }
    ...
    }
    

    Check out the below series for details. (Include download source code)

    http://www.wictorwilen.se/Post/Web-Part-Properties-part-1-introduction.aspx

    http://www.wictorwilen.se/Post/Web-Part-Properties-part-2-Editor-Parts.aspx