1

In Visual Studio 2010, is it possible to change the formatting of HTML documents such that it doesn't indent for <asp:*> sections? I'm trying to achieve this:

<asp:content contentplaceholderid="content" runat="server">
<!DOCTYPE html>
<html>
    <head>
    ...
    </body>
</html>
</asp:content>

Rather than this:

<asp:content contentplaceholderid="content" runat="server">
    <!DOCTYPE html>
    <html>
        <head>..</head>
        <body>..</body>
    </html>
</asp:content>

So that what eventually gets served to the browser has nothing before the <!DOCTYPE html>:

<!DOCTYPE html>
<html>
    <head>..</head>
    <body>..</body>
</html>

Which is just neater, and I think probably less error-prone.

I know I could just manually format the document and then never use the auto-format option (ctrl+k ctrl+d), but that's just annoying.

Robin Winslow
  • 10,908
  • 8
  • 62
  • 91

1 Answers1

1

For specific ASP tags

Tools -> Options -> Text Editor -> HTML -> Formatting -> then hit the button marked 'Tag Specific options' on the right pane -> then chose ASP.Net Controls on the left pane. Then choose the tag you wish to modify (asp:placeholder) and uncheck the checkbox marked 'Indent contents'.

For all server tags

In the "Tag specific options" windows, under "Default Settings" select "Server tag supports contents" and uncheck "Indent contents".

Robin Winslow
  • 10,908
  • 8
  • 62
  • 91
immutabl
  • 6,857
  • 13
  • 45
  • 76
  • 1
    Fantastic! This solves my problem because I have no problem with tweaking the formatting whenever I come across a new ASP control that's annoying me. Right now it's just `asp:content` I care about. However, I'll leave the question open for a bit in case anyone has a general solution. – Robin Winslow Sep 10 '12 at 10:26
  • I'll ask around and see if anyone can come up with the general fix. I suppose the other option is to approach the problem from another end and use some sort of minifying solution to strip out the whitespace from your generated HTML. Here are some interesting approaches: http://stackoverflow.com/questions/255008/minify-html-output-of-asp-net-application – immutabl Sep 10 '12 at 10:34
  • After playing around a bit I added a fix for all server tags – Robin Winslow Sep 10 '12 at 10:42
  • 1
    Ah damn. The problem with my solution is it applies to `
    ` too which I don't want. But still it's fine, I can just manually override that one.
    – Robin Winslow Sep 10 '12 at 10:48