Hiding default properties for a custom visual web part

走远了吗. 提交于 2019-12-04 20:24:32
Joel Jeffery

Here's one way to achieve this. In your EditorPart, mark the container of the other EditorParts as not Visible:

class EditorPartTest : EditorPart
{
    protected override void CreateChildControls()
    {
        Parent.Controls[1].Visible = false;
        Parent.Controls[2].Visible = false;
        base.CreateChildControls();
    }

    public override bool ApplyChanges()
    {
        return true;
    }

    public override void SyncChanges()
    {
    }
}

And use it from your web part like this:

public class VisualWebPart1 : WebPart
{
    public override EditorPartCollection CreateEditorParts()
    {
        ArrayList partsArray = new ArrayList();

        EditorPartTest editor = new EditorPartTest();
        editor.ID = this.ID + "_editorPart";
        partsArray.Add(editor);

        return new EditorPartCollection(partsArray);
    }
}

Then you should get a result like this:

http://joelblogs.co.uk/?attachment_id=10785

Hope this helps!

joel

joelblogs.co.uk

SharePoint Architect Blog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!