How to tell if page is in edit mode on a non-publishing site

点点圈 提交于 2019-12-09 16:26:33

问题


For our publishing sites we use the SPContext.Current.FormContext.FormMode enum to work out if the current page is in edit mode. I've seen that this does not work for a team site I'm currently working on. The FormMode is always set to 'Invalid'.

However, when I click edit page on a sample page, the page does switch to edit mode so there must be some other way of knowing that a page is in edit mode. So how can I tell if I'm in edit mode for a page living in a team site?

Cheers. Jas.


回答1:


For my scenario, I've found that I can make use of the WebPartManager object to find out if the current page is in edit mode.

Dim wpm As WebPartManager = WebPartManager.GetCurrentWebPartManager(Page)

result = wpm.DisplayMode.Name.Equals("design", StringComparison.InvariantCultureIgnoreCase)

The above code informs me whether the current page is in edit mode, since the webpart zone is in design mode. When not in design mode, the DisplayMode will usually be 'Browse'.




回答2:


The SPContext.Current.FormContext.FormMode cannot be used in OnInit; it is always Invalid there. Try it later; I use it in OnPreRender, for example.

The WebPartManager.DisplayMode can be used to check whether an editor part is active in the editor zone. It is an additional thing - you can have the page in edit mode without that. It dependes on what you want to check in your scenario.

By the way, use the read only members for the comparison, like: wpm.DisplayMode == WebPartManager.EditDisplayMode.

--- Ferda Prantl



来源:https://stackoverflow.com/questions/1807995/how-to-tell-if-page-is-in-edit-mode-on-a-non-publishing-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!