views:

114

answers:

2

I've created a web part with a custom editor part. Now I want to make changes in the behaviour of the web part if the editor part is open.

I can almost get it to work by setting a flag in the CreateEditorParts() method except that also fires when the user clicks "OK", "Apply" or "Cancel". The page will render without the editor part open but the web part still executes the CreateEditorParts method.

I haven't been able to find a property on the System.Web.UI.WebControls.WebParts.WebPart class that would indicate this, which seems like so obviously where it should be ;)

.. is there a way?

A: 

I haven't tested it but perhaps checking the visibility of the EditorPart itself might be an option.

Flo
+1  A: 

You could check to see if the page is in edit mode using the following:

 WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(Page);
 if (wpm.DisplayMode == WebPartManager.EditDisplayMode)
 {
      //Page is in edit mode
 }

I haven't tested this, but you could do this check in CreateEditorParts() and the code should only execute when the editorpart is open.

AlexWilson