Skip to content

Instantly share code, notes, and snippets.

@tiagoduarte
Last active July 24, 2017 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagoduarte/ba00b53a7e4f5696a1d2ca039d80042b to your computer and use it in GitHub Desktop.
Save tiagoduarte/ba00b53a7e4f5696a1d2ca039d80042b to your computer and use it in GitHub Desktop.
//check if page is in edit mode through page form mode
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
}
function checkIfEditMode()
{
//check if page is in edit mode through javascript
//must support SP2010, SP2013, publishing pages and wiki pages
//publishing page
if (document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode !== undefined)
{
//console.log("publishing page found!");
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if(inDesignMode === "1")
{
console.log("publishing edit mode active");
}
}
else
{
//wiki page
if (document.forms[MSOWebPartPageFormName]._wikiPageMode !== undefined) {
//console.log("wikiw page found!");
var wikiInEditMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (wikiInEditMode === "Edit") {
console.log("wiki edit mode active");
}
}
}
}
//check if page is in edit mode through webpart settings
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";
else
btnLink.Visible = false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment