views:

7125

answers:

7

Is there a way to comment out markup in an .ASPX page so that it isnt delivered to the client? I have tried the standard comments but this just gets delivered as a comment and doesn't prevent the control from rendering. Any suggestions would help

+1  A: 

Another way assuming it's not server side code you want to comment out is...

<asp:panel runat="server" visible="false">
        html here
</asp:panel>
Macka
I did delete this answer as its not strictly 'commenting out'. However, Joel's answer refers to mine so for the time being I've undeleted it.
Macka
+26  A: 
<%--
            Commented out HTML/CODE/Markup.  Anything with
            this block will not be parsed/handled by ASP.NET.

            <asp:Calendar runat="server"></asp:Calendar> 

            <%# Eval(“SomeProperty”) %>     
--%>

Source

Geoffrey Chetwood
+6  A: 
<%-- not rendered to brower --%>
Sklivvz
ORLY?.............
Jason Watts
+3  A: 

Yes, there are special server side comments: <%-- Text not sent to client --%>

stefano m
+1  A: 

I believe you're looking for:

<%-- your markup here --%>

That is a serverside comment and will not be delivered to the client ... but it's not optional. If you need this to be programmable, then you'll want Macka's answer :-)

Joel Martinez
+11  A: 

Bonus answer: The keyboard shortcut for commenting out anything in VisualStudio is Ctrl-KC . This works in a number of places, including C#, VB, Javascript, and aspx pages; it also works for SQL in SQL Management Studio.

You can either select the text to be commented out, or you can position your text inside a chunk to be commented out; for example, put your cursor inside the opening tag of a GridView, press Ctrl-KC, and the whole thing is commented out.

Herb Caudill
+4  A: 

FYI | ctrl + K, C is the comment shortcut in Visual Studio. ctrl + K, U uncomments.

Matthew M. Osborn