Html – Fix formatting of aspx file in Visual Studio

formattinghtmlvisual studiovisual-studio-2008xml

I have a file with a lot of this kind of thing in it:

    <asp:TableCell ID="TableCell9" runat="server">Company 
Organization:</asp:TableCell><asp:TableCell ID="TableCell10" runat="server">

How can I get the formatter to change it to shows like this:

<asp:TableCell ID="TableCell9" runat="server">Company Organization:</asp:TableCell>
<asp:TableCell ID="TableCell10" runat="server">

What I have tried:

I opened Tools->Options then browsed to Text Editor. I got a list of Languages. I selected HTML because that is the language that controls formatting for aspx files.

I changed "tag wrapping" to not have "Wrap tags when exceeding specified length" checked.

I then pressed ctrl+k, ctrl+d (Format the document). This did not fix the problem.


What I don't want to have to do:

Edit the file manually to fix all the tags.

Any ideas?

Best Answer

I was having the same problem, and I found the answer on Scott Gu's blog.

The solution is to setup the formatting rules in Visual Studio (right click on any tag, click on Formatting and Validation, click on Tag Specific Options)

When press ctrl-k, ctrl-d the document will format as per your settings. If a closing tag does not move to a new line, it's because there is no space between the end tag and what is preceding it. This happens because Visual Studio is being careful to not change how the page is rendered.

For the full blog post checkout Scott Gu's blog post.

http://weblogs.asp.net/scottgu/archive/2006/07/07/Tip_2F00_Trick_3A00_-Custom-formatting-HTML-in-Visual-Web-Developer-and-Visual-Studio-2005.aspx