SharePoint Designer Modifies HTML On Save

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.

8 Responses

  1. David Followes April 23, 2013 / 12:13 am

    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!

    • Chris Poteet April 23, 2013 / 10:14 am

      Hey David – I can’t quite tell what the issue is.

  2. David Followes April 23, 2013 / 10:51 pm

    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!

    • Chris Poteet April 25, 2013 / 9:37 am

      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.

  3. xr280xr December 4, 2013 / 12:23 pm

    Ya, SharePoint Designer 2007 is an unfinished, POS.

  4. John Cross February 14, 2014 / 12:21 pm

    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<

    • Chris Poteet February 14, 2014 / 12:32 pm

      Yep I mention that in the post.

Comments are closed. If you have a question please contact me.