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

2

8

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.

Tarrah answered 27/11, 2009 at 10:37 Comment(0)
T
8

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'.

Tarrah answered 27/11, 2009 at 11:13 Comment(1)
It's better to check wpm.DisplayMode.AllowPageDesign as it covers both "design" and "edit" cases - in first case web part zone is in design mode, in second one of its web parts is in edit mode - both cases show that the page is in edit modeIncrease
Y
3

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

Yeoman answered 21/4, 2010 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.