ASP.NET supports a little known feature called â€œserver-side commentsâ€ that you can use to completely disable code/controls/html in a page. Server-side comments in ASP.NET are delimited using a <%-- --%> syntax. For example:
Commented out HTML/CODE/Markup. Anything with
this block will not be parsed/handled by ASP.NET.
<%# Eval(â€œSomePropertyâ€) %>
One common question people ask is what the difference is between using client-side HTML comments and server-side comments. 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.
With server-side comments, the ASP.NET compiler ignores everything within these blocks at parse/compile time, and removes the content completely when assembling the page (like its contents werenâ€™t there at all). Consequently, any errors caused by mal-formed controls or issues with inline code or data-binding expressions within them will be ignored. The page is also just as fast with controls/code within server-side comments as if there were no controls/code on the page at all (there is no runtime performance overhead to them).