Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 530
Jason Evans Avatar asked Nov 27 '09 10:11

Jason Evans


People also ask

How do I know if SharePoint is in edit mode?

The edit mode of the page can be detected by the DisplayMode enumeration. In the modern SharePoint, pages and web parts are always in the same mode while in the classic SharePoint the web part will only detect the edit mode if the web part itself is in edit mode.

What happens when you unpublish a SharePoint page?

Unpublishing puts the page back into a draft state so it can't be viewed. However, the page will still appear in search results. If you don't want this to happen, you also need to remove permissions from the page: Go to the Pages library for the site.

Can I share an unpublished SharePoint page?

Details: Authors of SharePoint pages and news will be able to create private drafts. When a private draft is created, only the creator and site admins can see the page (including from within the Pages library). The creator can then share the private draft with other people to allow them to access and edit the page.

How do I go into edit mode in SharePoint?

To insert an Edit Mode panelBrowse to your publishing site. In the upper-right corner of the page, choose the Settings gear, and then choose Design Manager. In Design Manager, in the left navigation pane, choose Edit Master Pages or Edit Page Layouts, depending on what type of file you're editing.


2 Answers

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

like image 75
Jason Evans Avatar answered Oct 31 '22 05:10

Jason Evans


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

like image 25
Ferdinand Prantl Avatar answered Oct 31 '22 04:10

Ferdinand Prantl