Tuesday, October 13, 2009

SharePoint Web Part | Am I Editing ?

After (too) much searching, I've found a way to check if I'm at display mode, or the page is being edited at a given moment.

Here's how:

if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
// your code to support display mode
else if(Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit)
// your code to support edit mode


WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page);

if (wp.DisplayMode == WebPartManager.BrowseDisplayMode)
btnLink.InnerText = "Edit Page";
else if (wp.DisplayMode == WebPartManager.DesignDisplayMode)
btnLink.InnerText = "Exit Edit Mode";
btnLink.Visible = false;

My thanks to AvinashKT

No comments:

Post a Comment