-->

Hiding default properties for a custom visual web

2019-04-15 03:23发布

问题:

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