Is there a way to comment out markup in an .ASPX page?
asp.netMarkupCommentsasp.net Problem Overview
Is there a way to comment out markup in an .ASPX
page so that it isn't 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.
asp.net Solutions
Solution 1 - asp.net
<%--
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”) %>
--%>
Solution 2 - asp.net
Bonus answer: The keyboard shortcut in Visual Studio for commenting out anything 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.
Solution 3 - asp.net
FYI | ctrl + K, C is the comment shortcut in Visual Studio. ctrl + K, U uncomments.
Solution 4 - asp.net
<%-- not rendered to browser --%>
Solution 5 - asp.net
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 this answer :-)
Solution 6 - asp.net
Yes, there are special server side comments:
<%-- Text not sent to client --%>
Solution 7 - asp.net
While this works:
<%-- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ht_tv1.Default" %> --%>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Blank._Default" %>
This won't.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" <%--Inherits="ht_tv1.Default"--%> Inherits="Blank._Default" %>
So you can't comment out part of something which is what I want to do 99.9995% of the time.
Solution 8 - asp.net
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>