SharePoint Designer Modifies HTML On Save Chris Poteet, June 22, 2011June 17, 2011 The “Designer” in SharePoint Designer is used a little too liberally I think, but regardless here are two issues that SharePoint Designer does to your markup when saving the file. As far as I know this issue happens in both the 2007 and 2010 versions. Also, despite looking through all the program’s options, I can’t find one that causes this behavior to turn it off. Designer Removes Closing HTML Tags The first is that it removes closing HTML tags. This happens when you use the shorthand to close a SharePoint control. Here is what it looks like when this issue comes up. <p> <SharePointWebControls:fieldvalue id="BoxFourContent" FieldName="BoxFourContent" runat="server"/> </p> When saving the file (in this case a page layout), SharePoint Designer removes the closing paragraph tag. To change this instead of using the shorthand to self-close the SharePoint control use the longer version. <p> <SharePointWebControls:fieldvalue id="BoxFourContent" FieldName="BoxFourContent" runat="server"></SharePointWebControls:fieldvalue> </p> Designer Adds a Non-Breaking Space Character The second issue is SharePoint Designer adding a non-breaking space character when saving. Here is the markup that causes the issue. <h2> <SharePointWebControls:fieldvalue id="PageTitle" FieldName="Title" runat="server"/> </h2> In this case simply wrap the control in a span, and the issue goes away. Notice I am using a self-closing tag, yet for some reason in this instance (in the very same document) it doesn’t remove the closing HTML tag. Perplexing. <h2><span> <SharePointWebControls:fieldvalue id="PageTitle" FieldName="Title" runat="server"/> </span></h2> The first rule of a good web design tool: don’t mess with my markup. Related Posts SharePoint asp.nethtmlSharePoint Designer
I found a good hack-around for this: just add TWO closing tags. So, instead of adding around your element, add . Designer will remove one of the closing tags but leave the extra. http://yalla.itgroove.net/2012/01/sharepoint-designer-2007-2010-removing-closing-tags/ Reply
I’ve noticed that it removes …. tags on saving e.g. ” ” ” ” ” A” ” ” ” B” becomes: ” ” ” A ” ” B I have no answer for this but would like one! Reply
Sorry about the last reply, it should have said I’ve noticed that it removes .… tags on saving e.g. <div id=”radio”> <input type=”radio” id=”radio1″ name=”radio” checked=”checked”/> <label for=”radio1″>A</label> <input type=”radio” id=”radio2″ name=”radio”/> <label for=”radio2″>B</label> <input type=”radio” id=”radio3″ name=”> <label for=”radio3″>C</label> …. Gets reduced to <div id=”radio”> <input type=”radio” id=”radio1″ name=”radio” checked=”checked”/> A <input type=”radio” id=”radio2″ name=”radio”/> B <input type=”radio” id=”radio3″ name=”> C …. I have no answer for this but would like one! Reply
Not sure. I just looked in SharePoint Designer 2010 options because I thought there was an option for automatically correcting invalid XHTML. I didn’t see one however. Reply
I think I have found a solution for the closing tag issue. Don’t use short form tags (ie ending with a /), instead open and close the tag. So, with the following I found that the closing h1 tag was removed: >h1<>SharePointWebControls:TextField FieldName=”Title” runat=”server”/<>/h1< but when I changed it to this the closing tag was not removed: >h1<>SharePointWebControls:TextField FieldName=”Title” runat=”server”<>/SharePointWebControls:TextField<>/h1< Reply