Sometimes, in a Publishing site, you might want to give users the ability to leave comments on a page such as a news story, but you want the functionality embedded in the publishing page itself, so authors aren’t required to add the Note Board web part to each new page they create. You can do this by embedding the SocialCommentControl to your publishing page, like this:

<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>;
<SharePointPortalWebControls:SocialCommentControl runat="server" id="SocialComments"/> 

The thing is, when you do this, if there are no comments yet, the control displays a really long disclaimer that reads:

There are no notes posted yet. You can use notes to comment on a page, document, or external site. When you create notes they will appear here and under your profile for easy retrieval. Other people can also view the notes you post. Right click or drag and drop this link to your browser’s favorites or bookmarks toolbar to use notes to comment on external sites. Click here for more information about this and other social networking features in Microsoft SharePoint Server 2010.

Let’s be real; on a publishing site, you don’t need this long discourse. You don’t want to inform users that they can comment all over the place; you just want them to comment on this page. But how do you get rid of the message?

Unfortunately, this long message is embedded in javascript in the output of the page, which makes removing it rather difficult. Luckily, it’s possible to override javascript variables, provided your overridden value is embedded on the page after the variable that SharePoint wrote in the HTML, and before the script loads that displays the error mesage on the page.

The bottom line is, to get rid of the comments, add this line of javascript after your SocialCommentsControl on your page. (I personally chose to add it to a web control that I then added to my page layout.) Although it’s hard to read what the script is doing because it has escaped all the HTML characters into codes like “\u003c”, what you’ll notice is near the end is that there’s a <div> tag that has nothing in it. In the variable that SharePoint outputs to the HTML, it adds all the default text in there.

var __socialCommentInitialData_ctl00_PlaceHolderMain_SocialComments = '\r\n\u003cinput type=\u0022hidden\u0022 \r\n id = \u0022CommentPagingInfo_CurrentPage_ctl00_PlaceHolderMain_SocialComments\u0022\r\n value = \u00221\u0022 \u002f\u003e\r\n \u003cinput type=\u0022hidden\u0022 \r\n id = \u0022CommentPagingInfo_HasNext_ctl00_PlaceHolderMain_SocialComments\u0022\r\n value = \u0022false\u0022 \u002f\u003e\r\n \u003cdiv style=\u0022padding-left:5px;padding-right:5px\u0022\u003e\u003c\u002fdiv\u003e\u003c\u002fdiv\u003e'; 

Please note that this overrides a variable that SharePoint outputs to the HTML stream. That means that if at some later time, the script that SharePoint outputs to the page changes, this line of javascript could be potentially rendered worthless. However, for now it seems to work.

About Admin

Owner of Savvy Technical Solutions

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.