Hi everyone,
Nice to be back sharing my experiences with SharePoint 2013. It is been some time since my last post, this time I am posting a workaround to get the SocialCommentControl to work with Html5.
In SP2013 this control is deprecated, so I believe that’s why nothing was done to it. Once you add it to a page layout it breaks the markup.
I am talking about the control, so if you are using the SocialCommentWebpart the behaviour is the same, as it wraps up the control with webpart properties.
Googling this didn’t help, so I decided to reverse engineer the SharePoint assemblies and check the implementation. The problem lies on a html div tag. In Html 5 self-closing tags don’t work, but this control uses it, as below:
Code Snippet
- protected override void CreateChildControls()
- {
- base.CreateChildControls();
- if (!this.IsUPAEnabled)
- {
- string text = SPHttpUtility.HtmlEncode(StringResourceManager.GetString(LocStringId.SocialComment_NeedAuthenticatedMessage));
- text = string.Format(CultureInfo.InvariantCulture, "<span>{0}</span>", new object[]
- {
- text
- });
- this.Controls.Add(new LiteralControl(text));
- return;
- }
- this.Controls.Add(new LiteralControl("<div class=\"ms-socialCommentContents\" id=\"" + this.RootElementId + "\">"));
- if (this.IsShowNewArea)
- {
- this.RenderNewArea();
- }
- this.RenderEditArea();
- this.RenderErrorArea();
- this.RenderPagingControlContainer();
- this.Controls.Add(new LiteralControl("<div id=\"" + this.ClientID + "_PlaceHolder\" />"));
- this.Controls.Add(new LiteralControl("</div>"));
- }
Line 14 displays the problem. The tag div is self-closed, which doesn’t work in html 5.
The solution for this is simple. Because there is no closing tag, by adding a div closing tag does the trick.
Create a new class, inherit from SocialCommentControl and override the method CreateChildControls() by adding this closing tag. As below:
Code Snippet
- public class SocialCommentHtml5Control : SocialCommentControl
- {
- protected override void CreateChildControls()
- {
- base.CreateChildControls();
- this.Controls.Add((Control)new LiteralControl("</div>"));
- }
- }
That’s it. Add it to your page layout and use it on SP2013.
I hope it helps.
Cheers,
Reference:
Microsoft Forum
Click here to read the same content in Portuguese.