1

I have a custom web part which shows a different interface when in edit mode.

When in edit mode the default control panel displays on the right. When the user clicks OK, Cancel or Apply the web part stays in edit mode.

I want the custom web part to leave edit mode when the user selects OK or Cancel in the control panel.

Currently in the CreateChildControls method of the part I check the mode of the page by

            bool editMode = false;

            WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page);
            if (wpm.SelectedWebPart != null) {
                string selectedId = wpm.SelectedWebPart.ID;
                string thisId = this.ID;
                if (thisId.Equals(selectedId)) {
                    editMode = true;
                }
            }

After the user clicks OK or Cancel the editMode remains true.

Ideas? (thx)

1

You can make use of the WebPart.BrowserDesignMode Property to check whether the Web Part is in design mode and accordingly switch the display a different interface.

Read more here.. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpart.browserdesignmode.aspx

  • Since the WebPart.BrowserDesignMode Property is now obsolete, you can make use of the WebPartManager.DisplayMode property to achieve the same goal. Read more here.. msdn.microsoft.com/en- us/library/system.web.ui.webcontrols.webparts.webpartmanager.displaymode.aspx – Vivek Dec 14 '10 at 6:54
  • Well, the problem is clicking ok/cancel in the edit control panel does not take my part out of edit mode. Currently using bool editMode = false; bool thisPart = false; WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page); if (wpm.SelectedWebPart != null) { string selectedId = wpm.SelectedWebPart.ID; string thisId = this.ID; if (thisId.Equals(selectedId)) { thisPart = true; } } – dave Dec 14 '10 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.