views:

77

answers:

5

What is the difference between these types of comments in ASP.NET's ASPX markup page?

<%-- something here --%>

and the html comment

<!-- something here -->
+2  A: 

the first one would not appear in the final HTML output. the second one is how you comment in HTML and it will appear in the HTML output.

CD
+5  A: 

The first you will only see in the ASPX and not the rendered HTML Page

The second will be rendered as part of the HTML

John Hartsock
+1  A: 

This is a server side comment and will not appear in the HTML markup:

<%-- something here --%>

This is an HTML comment and will appear in the HTML markup, as it is part of it:

<!-- something here -->
Oded
+3  A: 

The first is a server side comment. It will stop the .NET code from executing.

The second is plain HTML comments. The .NET code inside the comments will still be executed on the server-side but the resulting markup will be commented out to the browser.

Scott Guthrie has a short but sweet blog post covering the differences a little more:

Tip/Trick: Using Server Side Comments with ASP.NET

Justin Niessner
+1  A: 

The <% ... %> comment is a so called server-side comment (and will not be shown in the final output). <!-- ... --> is a regular HTML comment (and will be shown in the browser by viewing the source).

The key difference is that with client-side comments it is the browser which is ignoring the content within them. Code/controls within client-side comments will still be executed on the server and sent down to the browser. As such, if there is a server error caused within them it will block running the page.

Read more about the differences here: Using Server Side Comments with ASP.NET 2.0

moontear