|
-
Feb 24th, 2011, 12:34 PM
#1
ASPX code being auto-formatted the wrong way
Hi,
I've had this problem for a while now, it seems to come and go (sometimes it happens, sometimes it doesn't) and I can't really figure out what's wrong.
Basically my aspx code will sometimes format automatically, except not in the way I want it to. I always structure html and xml-like code as such:
Code:
<parent>
<child />
<child>
<subchild />
<subchild />
</child>
</parent>
This way I can quickly see which tags belong to which, and I think this is the usual way html is formatted, right?
Anyway, suppose that I have this code in my aspx code window (don't mind that it's not aspx code, that's not the point), then sometimes VS will automatically format it to this:
Code:
<parent>
<child />
<child>
<subchild />
<subchild /></child></parent>
Basically it seems to put all closing tags on the last line, leaving me sometimes (with many nested tags) with an extremely long line at the end, making it completely impossible to see the structure of my code.
Here is an actual example. This is how I wrote my code:
xml Code:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Login</h2>
<p>
<asp:Label runat="server" ID="lblMessage" Font-Bold="true" ForeColor="Red" />
</p>
<p>
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>Gebruikersnaam:</asp:TableCell>
<asp:TableCell Width="35px" />
<asp:TableCell>
<asp:TextBox runat="server" ID="txtUsername" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Wachtwoord:</asp:TableCell>
<asp:TableCell Width="35px" />
<asp:TableCell>
<asp:TextBox runat="server" ID="txtPassword" TextMode="Password" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</p>
<p>
<asp:Button runat="server" ID="btnOK" Text="Login" OnClick="btnOK_Click" />
<asp:Button runat="server" ID="btnCancel" Text="Annuleren" OnClick="btnCancel_Click" />
</p>
</asp:Content>
Now when I change my view to 'Split view' (to see both code and design in one window) and start clicking in the design view, sometimes (not always for some reason), VS seems to think I want to format my code, and it changes it into this mess:
xml Code:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Login</h2>
<p>
<asp:Label runat="server" ID="lblMessage" Font-Bold="true" ForeColor="Red" />
</p>
<p>
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>Gebruikersnaam:</asp:TableCell>
<asp:TableCell Width="35px" />
<asp:TableCell>
<asp:TextBox runat="server" ID="txtUsername" />
</asp:TableCell></asp:TableRow><asp:TableRow>
<asp:TableCell>Wachtwoord:</asp:TableCell><asp:TableCell Width="35px" />
<asp:TableCell>
<asp:TextBox runat="server" ID="txtPassword" TextMode="Password" />
</asp:TableCell></asp:TableRow></asp:Table></p><p>
<asp:Button runat="server" ID="btnOK" Text="Login" OnClick="btnOK_Click" />
<asp:Button runat="server" ID="btnCancel" Text="Annuleren" OnClick="btnCancel_Click" />
</p>
</asp:Content>
This is actually not as bad as it gets, I've seen it way worse, but still I cannot read this mess anymore and I have to go back and manually format the code again until it just happens again...
Using Format Document helps a little bit but it still isn't the way I want it... After Format Document, the Table for example is condensed into this:
xml Code:
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>Gebruikersnaam:</asp:TableCell>
<asp:TableCell Width="35px" />
<asp:TableCell>
<asp:TextBox runat="server" ID="txtUsername" />
</asp:TableCell></asp:TableRow>
<asp:TableRow>
<asp:TableCell>Wachtwoord:</asp:TableCell><asp:TableCell Width="35px" />
<asp:TableCell>
<asp:TextBox runat="server" ID="txtPassword" TextMode="Password" />
</asp:TableCell></asp:TableRow>
</asp:Table>
It still places many closing tags on a single line for some reason.
I have made several journeys through the many Text Editor options, but I have not yet been able to fix this issue... I've looked at the HTML options, XML options, whatever seems likely, but I cannot figure out the correct combination of options that will make VS auto-format my code in the usual way, instead of just dropping multiple closing tags on one line...
Any help?
-
Feb 25th, 2011, 01:42 AM
#2
PowerPoster
Re: ASPX code being auto-formatted the wrong way
Hi,
I have the same problem in VS 2008. VS always adds 100's of lines of spaces inbetween my markup and it really annoys me. I fixed it once but the next time I just left it the way it is
-
Feb 25th, 2011, 02:31 AM
#3
Re: ASPX code being auto-formatted the wrong way
Hello,
If you don't "like" the default formatting options of the "Format Document" (CTRL + K, D) command, then you can tell Visual Studio what you preferences are.
Take a look at this short video:
http://scottcate.com/Tricks/018/
Hope that helps!
Gary
-
Feb 25th, 2011, 03:48 AM
#4
Re: ASPX code being auto-formatted the wrong way
Yeah I've played around with those options, but they don't seem to work. For example, in the 'tag specific options' I added the <asp:Table> tag for controls and told VS to insert a newline before, in between, and after, (same for <asp:TableRow> and <asp:TableCell>) but after auto-formatting it still puts the closing tags on one line... </asp:TableCell></asp:TableRow></asp:Table>. It simply doesn't want to listen... lol.
-
Feb 25th, 2011, 04:02 AM
#5
Re: ASPX code being auto-formatted the wrong way
Which option were you playing with specifically? Text Editor | HTML? Or something else?
Gary
-
Feb 25th, 2011, 11:30 AM
#6
Re: ASPX code being auto-formatted the wrong way
Text Editor - HTML / XML / XAML and probably a few others. In the HTML options I also used the tag specific options button but still no luck. If I have some time later today I'll show you the exact settings and how the autoformat kicks into effect.
-
Feb 25th, 2011, 01:24 PM
#7
Re: ASPX code being auto-formatted the wrong way
Ok, I got a bit further. The tag specific options I have now are this:
Code:
Default Settings
Client tag supports contents
Line breaks = Before opening, within, and after closing
Indent contents
Server tag suppors contents
Line breaks = Before opening, within, and after closing
Indent contents
ASP.NET Controls
asp:Table / asp:TableCell / asp:TableRow
Line breaks = Before opening, within, and after closing
Indent contents
(I am trying to format the Table correctly at the moment, hence those options).
Judging from the example this should give me what I want.
However, for some reason if my code is formatted as such:
Code:
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell> ... </asp:TableCell></asp:TableRow></asp:Table>
(This happens automatically for some reason, haven't figured out yet why)
Now if I do Edit - Advanced - Format Document, it does not work. It does not change anything. However, if I put the closing tags on separate lines manually, but still not indented properly, like this
Code:
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell> ...
</asp:TableCell>
</asp:TableRow>
</asp:Table>
Now after Format Document it DOES format it correctly:
Code:
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>
...
</asp:TableCell>
</asp:TableRow>
</asp:Table>
So it seems to be quite buggy to me, it simply ignores closing tags that are on the same line when it should actually put them on a new line as per the options I chose...
-
Mar 13th, 2011, 10:17 AM
#8
Re: ASPX code being auto-formatted the wrong way
Hello Nick,
Did you ever do any more investigation into this? I wasn't able to get it to do what you wanted 
Gary
-
Mar 13th, 2011, 06:48 PM
#9
Re: ASPX code being auto-formatted the wrong way
I tried a few more times, never got any further though. Automatic formatting is still 'wrong'.
-
Mar 14th, 2011, 04:33 AM
#10
Re: ASPX code being auto-formatted the wrong way
Hmmm, I still think that there MUST be a way to do this, and I would be VERY surprised if there isn't.
If I get a chance, I will do some more digging on this.
Gary
-
Apr 19th, 2011, 01:30 PM
#11
New Member
Re: ASPX code being auto-formatted the wrong way
I am experiencing the same problem. I want my Heading1 elements to be on one line. I have set the proper "Tag Specific Options" after creating an h1 "Client HTML Tag", but it never puts my code on one line. It gets formatted differently depending on white space use before issuing the format command, but never like I want it. VS 2008 was the same way. This is a real pain.
, Lee
-
Apr 20th, 2011, 01:16 AM
#12
Re: ASPX code being auto-formatted the wrong way
Hello Lee,
This is starting to sound more and more like a bug within Visual Studio itself. You might want to think about submitting a but over at:
http://connect.microsoft.com/
With steps to reproduce, and see what they say.
Gary
-
Apr 20th, 2011, 03:02 AM
#13
New Member
Re: ASPX code being auto-formatted the wrong way
The last several times I tried, Visual Studio was not one of the "products accepting bugs or suggestions". That's a great way to stifle feedback, Microsoft. I'll set a reminder in Outlook to keep trying tell you about your bugs, hoping that one day you're willing to listen. Sheesh.
-
Apr 20th, 2011, 03:05 AM
#14
New Member
Re: ASPX code being auto-formatted the wrong way
-
Apr 20th, 2011, 07:51 AM
#15
Re: ASPX code being auto-formatted the wrong way
 Originally Posted by Lee C.
The last several times I tried, Visual Studio was not one of the "products accepting bugs or suggestions". That's a great way to stifle feedback, Microsoft. I'll set a reminder in Outlook to keep trying tell you about your bugs, hoping that one day you're willing to listen. Sheesh.
Oh really! I was not aware of that!
Looks like there have been a number of reports about this functionality though
-
Apr 20th, 2011, 09:50 AM
#16
Re: ASPX code being auto-formatted the wrong way
Judging from that page, it seems like it is a bug after all and they won't be fixing it until the next release... But then I don't understand why not everyone can reproduce it? I doubt it's a matter of 'not noticing' it because it is VERY noticeable if 8 closing tags get placed on one line....
-
Apr 20th, 2011, 10:47 AM
#17
New Member
Re: ASPX code being auto-formatted the wrong way
This bug has existed for a long time. I'm nearly certain that I reported it in the 2008 release.
Here's a report from 1/16/2006!
http://connect.microsoft.com/VisualS...is-not-applied
Don't get your hopes up for a fix. I'm surprised Microsoft didn't do the old remove-the-feature-instead-of-fixing-it fix!
How many VS realeases (including SPs) have there been since 1/16/2006? Wow.
-
Apr 20th, 2011, 10:50 AM
#18
New Member
Re: ASPX code being auto-formatted the wrong way
 Originally Posted by NickThissen
...it seems like it is a bug after all and they won't be fixing it until the next release...
I wish I could believe that. Connect is a place to gather votes. If the bug fails to get lots of votes, it gets no love from Microsoft. Pure democracy is bad. The Founding Fathers knew it; I wish Microsoft did.
-
Apr 20th, 2011, 02:11 PM
#19
Re: ASPX code being auto-formatted the wrong way
It is difficult or them I guess. With such a huge code base, they have to pick carefully about what getting included.
Gary
-
Apr 20th, 2011, 02:23 PM
#20
Re: ASPX code being auto-formatted the wrong way
I can believe it's difficult, but it's also a huge pain! It makes maintaining aspx code simply impossible. I already find it difficult to read aspx/html code (compared to other languages) for some reason, even if properly formatted, but if the formatting goes haywire like this I can't make sense of it anymore...
Imagine writing C# code, and each time you switch to the designer the code editor screws up and creates something like this mess
Code:
public
class Someclass : Entity<TValue
,
TKey>
{ public SomeClass(int i) { this.Value = i;
}}
That'd be pretty horrible, right..? That's what it's like for me. I have to go back and re-format the aspx code every time I want to properly read it, and then as soon as I switch to design view it's messed up again...
I was actually looking at creating code editor add-ons so I could write my own formatter but at the moment that's not worth the trouble... I thought it would be easy in VS2010 but it's still pretty complicated.
-
Apr 20th, 2011, 02:30 PM
#21
Re: ASPX code being auto-formatted the wrong way
Hey,
I honestly can't say that I have been plagued by this issue though. The example that you gave dealt specifically with an asp:Table. Do you have other examples where this happens, or is it only with this particular tag? The reason that I ask is that I typically don't use Tables (either HTML or ASP.Net) in my ASPX markup.
Gary
-
Apr 20th, 2011, 03:58 PM
#22
New Member
Re: ASPX code being auto-formatted the wrong way
 Originally Posted by gep13
The example that you gave dealt specifically with an asp:Table. Do you have other examples where this happens, or is it only with this particular tag?Gary
As mentioned, for me it was for <h1>, as well as h2, h3, etc. I think it's an issue for any tag that I have to add to the list (versus the built-in list).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|