Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix formatting of aspx file in Visual Studio?

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?

like image 490
Vaccano Avatar asked Jun 04 '10 21:06

Vaccano


People also ask

How do I fix formatting in Visual Studio 2019?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

How do I enable formatting in Visual Studio?

The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations: On Windows Shift + Alt + F. On macOS Shift + Option + F. On Linux Ctrl + Shift + I.


1 Answers

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

like image 192
TheLukeMcCarthy Avatar answered Sep 24 '22 01:09

TheLukeMcCarthy