HTML Comments, Other Comments and Some VS Tips

by ashic 1. September 2008 21:50

 

I just found out something really weird about HTML comments. Apparently, according to standards, you can't do this:

<!--  comment ------------------------ -->

That is, you can't put two or more ‘-‘s inside a comment. It works as expected in IE7, but it breaks down horribly in FireFox. FireFox simply renders the comment to the user, which is pretty useless as that's not what comment are for!!. The standards "recommend" developers to not put two or more consecutive ‘-‘s inside an html comment. Now, that's weird. If there are specific delimeters like <!-- and  -->, then I should be able to use any part of those delims (but not the whole) inside a comment, shouldn't I?

Since, we're in the vicinity of comments, let's look at some for reference:

HTML: <!-comment -->

C#: //single line comment

/* multiline comment */

VB.NET: ‘single line comment

SQL: /* multiline comment */

-- single line comment

Asp.Net markup (aspx): <%-- comment --%>

 

Now here's a neat trick regarding commenting and uncommenting code in Visual Studio and Visual Web Developer. In any code editor, highlighting a bit of code (be it VB.Net, C# or aspx markup), if you press ctrl+(k, c) [That is, press k and then c while holding down control), it'll automagically comment out that part using the comments that apply to the selected code (so, // in C# and ‘ in VB.Net etc). To uncomment, highlight and hit ctrl+(k,u). One thing to keep note is that the uncomment will work if you select any part of the beginning of a line for VB.Net and C#. For aspx markup though, you must select from <% to the closing %> for the ctrl+(k,u) uncommenting to work.

Also, asp.net <%-- --%> comments work server side. So, nothing in them are visible to the compiler. HTML comments work client side. So, if you put anything inside <!-- -->, it'll be visible to the compiler. Hence, if you're trying to comment out some part of markup that fails to compile, you must use the server side <%-- --%> comments.

 

One last trick for today is the auto formatting of code. In a code editor in Visual Studio or Visual Web Developer, you can select some code and hit ctrl+(k,f). This'll auto format that part of the code. This is immensely helpful for formatting aspx markup really quickly. Keep in ind though, that your code must be valid and error-free. If the ctrl+(k,f) trick doesn't work, it's a sign that there's a problem with code/markup.

Hope that helps.

Share or Bookmark this post…
  • Facebook
  • DotNetKicks
  • Digg
  • LinkedIn
  • Technorati
  • del.icio.us
  • Google
  • Live
  • Tumblr
  • msdn Social
  • Ping.fm
  • Reddit
  • Slashdot
  • StumbleUpon
  • TwitThis
Categories: ASP.NET

Comments

8/24/2008 3:21:15 PM #

http://

I don't think so, man.  You're wrong about the --'s in comments.  It's working fine on Firefox 3.0.1 in any case.  Are you sure something else isn't wrong with your HTML?

http://

8/24/2008 9:32:13 PM #

That's weird. I just made a html file with only the comment. You seem to be right. But then again, I run my other page (which is quite large and heavy with javascript). If I put in -- in comments, FF just spits out the comment. If I put anything but -- in the comment, there's no problem. Btw...the page validates as xhtml, so no problem there.

As for my reference, look at this:
http://forums.asp.net/t/1311909.aspx

Lance went overboard with the references Smile

HeartattacK

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.1.0
Theme by Ashic Mahtab

Need an expert?

Ashic Mahtab
ashic@live.com
(+44) 07879927393

Stats

Featured Ads

 

Donations

I maintain this site and create all content entirely in my own time just to help you guys out. If you find the stuff helpful, or cool or just like what you see, I'd appreciate you chipping in to help out with the hosting costs. It's easy to do so - just click the button below - no amount is too low :)