Comment on an ASPX page

A

Andrew Chalk

In the HTML section of an ASPX page, how do i comment out a line?

I thought it was <! but that doesn't work.

Thanks!
 
K

Ken Cox [Microsoft MVP]

Hey Andrew,

Don't forget the exclamation mark:

<div>
<!-- An HTML comment -->
<%'<!-- This is an ASPX comment --> %>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
 
A

Andrew Chalk

But the following does not seem to work:

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

Bob Lehmann

It work for me.
<!-- <asp:label id="Label1" runat="server">Label</asp:label> -->
renders as ....
<!--<span id="Label1">Label</span>-->
in the browser.

Bob Lehmann
 
J

Justin Lovell

Hi,

The reason why your example does not "work" is because the ASP.NET page
parser does not see that the label is within HTML comments. Thus, it will
output the 'normal' HTML inbetween the label tags.

For you to comment on server controls, you could try the following:

C#: <% // <asp:label runat="server" /> %>
VB.NET: <% ' <asp:label runat="server" /> %>

I hope that helps,
Justin
 
C

clintonG

Try the documentation [1].

If you're using Visual Studio you can apply and remove server-side comments
using tools on the Standard toolbar.
I also use Ctrl-K/Ctrl-C and Ctrl-K/Ctrl-U noting VS2005 Beta 2 which I
continue to use until RTM remains somewhat buggy when trying to
Ctrl-K/Ctrl-U to remove comments. More keyboard shortcuts can be reviewed
here [2] as well as other sites.

To avoid problems use the server-side comment syntax Microsoft recommends.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1]
http://msdn.microsoft.com/library/d...us/cpgenref/html/cpconserver-sidecomments.asp
[2] http://safari.oreilly.com/?XmlId=0-596-00360-9/mastvsnet-APP-C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top