Tuesday, 15 October 2013

SharePoint 2013: How can I tell if my page is in edit mode?

The solution lies in the object model: Microsoft.SharePoint.SPContext.Current.FormContext.FormMode
It returns a SPControlMode enumeration.

An example usage of the code is as follows:

if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
  // Do display stuff
else if ( Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit )
  // Do edit stuff

No comments:

Post a comment