开发者

What is the difference between these comments

开发者 https://www.devze.com 2023-01-22 00:51 出处:网络
What is the difference between these types of comments in ASP.NET\'s ASPX markup page? <%-- 开发者_运维问答something here --%>

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

<%-- 开发者_运维问答something here --%>

and the html comment

<!-- something here -->


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


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


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


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.


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 -->
0

精彩评论

暂无评论...
验证码 换一张
取 消