Last active
July 24, 2017 08:26
-
-
Save tiagoduarte/ba00b53a7e4f5696a1d2ca039d80042b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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