Server side comments with ASP.NET

Summary Haiku

  • server-side comments
  • I feel I should have known this
  • now I guess I do

Ok, I feel foolish for not having known this, but now I know it, and want to share. If you have some ASP.NET code that you want to comment out, you can just wrap the code with server side comments. They’re just like regular HTML comments, except the exclamation point has been replaced with the percent sign, i.e. <%– and –%>. So to comment out the following:


<asp:Panel runat="server" ID="Panel1" Visible="false">
<asp:Label runat="server" ID="firstNameLabel" AssociatedControlID="firstName" Text="First Name: " />
<asp:TextBox runat="server" ID="firstName" />
</asp:Panel>

Just surround the code with <%– and –%>, as below:


<%--
<asp:Panel runat="server" ID="Panel1" Visible="false">
<asp:Label runat="server" ID="firstNameLabel" AssociatedControlID="firstName" Text="First Name: " />
<asp:TextBox runat="server" ID="firstName" />
</asp:Panel>
--%>

Before learning this I would have changed all the ‘runat=”server” ‘ bits to ‘xrunat=”server” ‘, which is…ugly. I guess it’s never too late to learn new things.

Jeff Sargent is a .NET web developer and designer. He loves the Web and tries to make it better through usable, accessible design.

Get the RSS feed | About Jeff | Get in touch

Comments

  1. 1
    Graham wrote on June 17, 2008

    Very cool. I would usually do runat=”serverXXX”, which sounds a little dirty.

Leave a Comment