1

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?

4

3 回答 3

2

您可以使用以下命令检查页面是否处于编辑模式:

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

我没有对此进行测试,但是您可以在 CreateEditorParts() 中进行此检查,并且代码仅应在编辑器部分打开时执行。

于 2009-10-30T08:50:47.810 回答
0

我尚未对其进行测试,但也许检查 EditorPart 本身的可见性可能是一种选择。

于 2009-10-30T08:27:29.160 回答
0

如果它可能对其他人有帮助:

您的 WebPart 可能会在多处发现其EditorPart正在显示。其中之一可能适合您的场景:

在 WebPart 中:

在编辑器部分:

  • EditorPart.SyncChanges:“[...] 调用 SyncChanges 方法的另一种情况是 WebPart 控件进入编辑模式时。”
  • EditorPart 生命周期方法之一(例如 OnInit /OnLoad)。无论如何,EditorPart通过EditorPart.WebPartToEdit属性具有对父WebPart 的引用。
于 2011-10-24T00:26:05.767 回答