[aus-dotnet] ASPX Formatting in VS.NET Tips

Here is an email I sent to the aus-dotnet list today that I thought I’d share with my blog readers (well, those blog readers who aren’t also on the list!)

Thought I’d also just copy and paste the exact subject line too ;)

Hi guys,

I know that many web developers on the list and elsewhere are always annoyed
when VS.NET HTML Designer always messes up their nicely tabulated code.

So I’ve got a tip (or more) for you guys that i’ve found to work quite
nicely.

If you’ve got a TextEditor such as TextPad (http://www.textpad.com)
installed, download a plugin called “XML Tidy”. (Available here:

http://www.textpad.com/add-ons)

Then all you need to do is load your .aspx page into textpad, and run the
XML Tidy tool, and it’ll reformat your document nicely.

A few other points of importance:
1) Formatting is done using WhiteSpaces. So, I’ve used another TextPad add
on called Tabout, which converts whitespaces to tabs.
2) XML Tidy expects your document to be well-formed XML documents (which the
ASPX pages aren’t).
It will give you a warning asking if you want to continue anyway, click yes,
and it’ll format it.
3) Also, make sure if you are linking to an external stylesheet using the
<link …> tag, close it by changing it to <link …/>
Basically convert it all to be XHTML compliant. [Eg: <br> changes to <br/>,
<hr> to <hr/>, <meta ...> to <meta .../> etc...]

4) When you add these addons as external tools (as per the instructions) you
can just open the document up in textpad, and they (the tools) will have a
ctrl+1 or ctrl+2, etc… assigned to them for easy/quick access.

At first I was really cautious with it, in case something went horridly
wrong, but after quite a number of successes, I can post and say it worked
quite well.

But as always, be careful, tools can’t always be trusted :)

I’m sure there is a way to just add it as an external tool for VS.NET. But I
haven’t had time to investigate (after I’ve added it as an external tool in
VS.NET, XML Tidy gives a dialog box “You must pass the window handle of the
window containing the text to be operated on.”).

If you’re happy with messed up HTML then ignore this :)

Cheers,

William

Oh, and HTMLTidy doesn’t work as well, because from what i’ve read, it doesn’t like the

Update: For replacing all of your <br> tags into <br/>, etc… Just do a find and replace, that is the easiest solution!

2 Responses to “[aus-dotnet] ASPX Formatting in VS.NET Tips”

  1. Mister Ken Says:

    Thanks for posting that!

  2. IrOnFiSt Says:

    http://www.textpad.com either doesn’t exist or their servers are down!! :-(