Hiding default properties for a custom visual web part

天大地大妈咪最大 提交于 2019-12-06 13:20:27

问题


Is there a way of hiding Common properties of Web Parts? The Layout or appearance section for example.

I have created a new visual web part and I wan't to make it very easy to edit for the administrators and they don't need the standard layout / appearance settings when they go to 'edit web part'

Any ideas how to hide the base properties from the edit panel? Been searching all over but can't see anything in the documentation.


回答1:


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



来源:https://stackoverflow.com/questions/7311196/hiding-default-properties-for-a-custom-visual-web-part

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