Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)

share|improve this question
add comment

1 Answer 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

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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