Tuesday, July 31, 2012

How to know if the Page is in Edit Mode - C#

For a page we need to use:
if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
  {
   //  display mode
  }
  else // Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit
  {
   //  edit mode
  }



and for webpart pages:

   WebPartManager mgr = this.WebPartManager;
 if (mgr.DisplayMode == WebPartManager.EditDisplayMode)
     {
        // edit mode
     }
  else
     {
  //  display mode
     }

No comments:

Post a Comment