Identify whether the Page is in EditMode or in Design Mode in SharePoint 2013 using Javascript.

Sathish Nadarajan
 
Solution Architect
December 3, 2014
 
Rate this article
 
Views
12931

I faced one interesting requirement like, from a publishing page, I would like to know whether the page is in Edit Mode or in Design Mode. Based on that, we need to update one property value as well on the PageLayout. Let us see how to do that in SharePoint 2013 using Javascript.

On the PageLayout, I added a JS file. On the Document.Ready Event,

 $(document).ready(function ($) {
 
     var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
 
     if (inDesignMode == "1") {
         // page is in edit mode
         $(".MyPropertyValue").val("");
     }
     else {
         // page is in browse mode
     }
 });
 

The Layout would be the same when you are in EditMode as well as on the Design Mode. Though it is very simple, this will be very useful, when we deal with the PageLayouts and Javascript.

On the PageLayout, I have the Field as,

 <SharePointWebControls:TextField  runat="server" FieldName="MyProperty"  CssClass="MyPropertyValue" />

Happy Coding.

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment