in

Platinum Bay

Peace, Love, and...

This Blog

Syndication


.NETicated

Easier ASP.NET Commenting

In my Visual Studio Tips and Treats talk, I discuss proper code commenting for ASP.NET pages. Let's review.

It is generally a bad idea to use regular HTML comments to comment out ASP.NET server and user controls. Why? Because the commented controls still be parsed and rendered. Imagine commenting out a large data grid, but still having all that content sent to the client. Worse yet is sensitive information that has been 'removed', but is still showing up in the client-side source.

Example:

<!--<asp:Label ID="Label1" runat="server" Text="SocialSecurityNumber" />-->

The recommended approach is to use server-side comments (Ctrl+K+C). Server-side comments prevent the commented code from being parsed and sent to the client.

Example:

<%--<asp:Label ID="Label1" runat="server" Text="SocialSecurityNumber" />--%>

Now for the good part. I just discovered, by accident, that you don't need to highlight the entire region you want commented. You can simple place the cursor inside the tag you want commented, and use the keyboard command Ctrl+K+C to comment, or Ctrl+K+U to uncomment. Up until now, I had either used the mouse or Shift+[Down|Up]Arrow to select the region I wanted to comment out.

Published Dec 23 2007, 03:00 PM by Steve
Filed under: ,

Comments

February 9, 2010 5:42 PM

asp.net comments using server side comments that can disabled code controls in the page. Because AJAX enabled the comment form.

 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews is an independent consultant, INETA speaker, and Microsoft MVP for Visual Studio ALM. He has been working in technology for over ten years focusing on custom application development and Application Lifecycle Management. Steve is also Microsoft and IBM certified and a community fanatic having led sessions at nearly 100 events across North America. When he's not developing software solutions or engaging with the community about software technology, Steve is a closet singer and songwriter and plays the guitar and keys. Occasionally, Steve even gets to sleep. Occasionally.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.