Monday, May 31, 2010

SharePoint 2010: The current page has been customized from its template. Revert to template.

The annoying warning ‘The current page has been customized from its template. Revert to template’ comes up in page when a page is customized . For example you have created a page mypage.aspx with master page ‘default.master’. Now if you change the master page to custom.master then you will find the message ‘The current page has been customized from its template. Revert to template’. If you make any change to the page then the page will be customized and you will find a message. I think by myself that the message is pretty much annoying and  concerning to any SharePoint developer/administrator. Till now there’s no known settings to stop the message.

 

First Solution (extreme solution):

The first solution I have found in sharepoint forum. The solution is to comment out the section in master page which shows the message. As per the solution, find the following section in master page and comment it out.
<div id="s4-statusbarcontainer">
    <div id="pageStatusBar" class="s4-status-s1">
    </div>
</div>

So the solution in this case to hide div permanently from the master page. But the problem here might be that if the same div is used to show another useful message then user will not find the message.

 

Second Solution (soft solution):

Another solution might be not to remove the div from master page. Rather to hide/show the message on the client side on page load. Remember the default master page is V4.master, so in case of default master page, use V4.master instead of Default.master. The logic is:
  1. set the div’s visibility to ‘none’ as shown below. So the div is not visible by default
    <div id="s4-statusbarcontainer" style="display:none">
        <div id="pageStatusBar" class="s4-status-s1">
        </div>
    </div>
  2. Run a script on page load which will check the message inside the div. And based on the message the div will be visible or not. I have put the following script in the master page’s head section. The script check if the display message is not ‘The current page has been customized..’ and if not so then display the message:
    <head>
    ...........................
    
    <script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(hideWarning, "sp.js");
    function hideWarning() {
        var statusbarContainer = document.getElementById('s4-statusbarcontainer');
        if (statusbarContainer != null) {    
            var messageSpan = document.getElementById('status_1_body');
            if (messageSpan != null) {
                if (messageSpan.innerHTML.indexOf('The current page has been 
                                  customized from its template.') == -1)
                    statusbarContainer.style.display = 'inline';
            }
        }
    }
    </script>
    </head>
    In the above code snippet, the method ‘ExecuteOrDelayUntilScriptLoaded’ ensures that the method hideWarning is not invoked until the base SharePoint JavaScript file sp.js is loaded.

My final judgment is that SharePoint should provide a settings from site collection/web level to enable/disable the warning. sometimes admin wants to accept the warning but don’t want to show it to end users. Hope some SharePoint team will heed into this. Till that day we, sharepoint developer, need to find a way out. Hope someone out there will get a better idea.

10 comments:

  1. Hmmm...very buggy. What is really odd is that if you make the change several times in Designer and then click on 'Revert to Template', it will eventually keep the new change yet the Revert to Template message will go away. Not exactly smooth - but my work saved and annoying message is gone! :)

    ReplyDelete
  2. In your case the changes were kept intact but in some cases the changes are reverted. So you can't predict if the changes will be kept or not.

    ReplyDelete
  3. Please use brackets EVERYTIME after IF, otherwise it's bugs up ahead....

    ReplyDelete
  4. Second Solution works great on our SharePoint Enterprise sandbox.

    Thanks Sohel!!!

    ReplyDelete
  5. Another alternative is to use the SharePoint:SPSecurityTrimmedControl class and its Permissions attribute arround the pageStatusBar div tag.

    ReplyDelete
  6. Nice.. I had to make some changes to make it work for me, though. I used "sp.ribbon.js" instead of "sp.js" and I changed the messageSpan.innerHTML.indexOf conditional around and added "display: none;" instead of inline.

    For some reason, it wouldn't work properly the original way.



    ExecuteOrDelayUntilScriptLoaded(hideWarning, "sp.ribbon.js");
    function hideWarning() {
    var statusbarContainer = document.getElementById('s4-statusbarcontainer');
    if (statusbarContainer != null) {
    var messageSpan = document.getElementById('status_1_body');
    if (messageSpan != null) {
    if (messageSpan.innerHTML.indexOf('The current page has been customized from its template.') !== -1){
    statusbarContainer.style.display = 'none';
    }
    }
    }
    }

    ReplyDelete
    Replies
    1. Your solution solved my problem while the first solution didn't
      thank you

      Delete
  7. This worked for me without messing with the master page:

    ExecuteOrDelayUntilScriptLoaded(hideWarning, "sp.js");
    function hideWarning() {
    var statusbarContainer = document.getElementById('s4-statusbarcontainer');
    if (statusbarContainer != null) {
    var messageSpan = document.getElementById('status_1_body');
    if (messageSpan != null) {
    if (messageSpan.innerHTML.indexOf('The current page has been customized from its template.') != -1)
    statusbarContainer.style.display = 'none';
    }
    }
    }

    ReplyDelete
  8. Thankx Sohel & RamGen, I just pasted above script snippet in my custom .js & it started working :)

    ReplyDelete