Monday, March 31, 2008

Using Server Side Comments with ASP.NET 2.0



This blog post summarizes the best approach for commenting the code in UI.


We know the ways are Client Side and Server Side.


Let see what the difference is between using Client-Side HTML comments [!--  --> ] and Server-Side comments [<%-- --%>]


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).


For server-side comments, you can use the shortcuts - “Ctrl-K, Ctrl-C” to comment a block and “Ctrl-K, Ctrl-U” to uncomment one.


Hope this helps.



Arun Manglick


No comments:

Post a Comment