是否有一种方法可以注释掉.ASPX页面中的标记,这样它就不会被交付给客户端了?我已经尝试了标准注释<!-- -->,但这只是作为注释交付,并没有阻止控件的呈现。


当前回答

是的,有一些特殊的服务器端评论:

<%-- Text not sent to client  --%>

其他回答

另一种方法是假设你想注释掉的不是服务器端代码……

<asp:panel runat="server" visible="false">
    html here
</asp:panel>
<%--
            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”) %>     
--%>

<%-- not rendered to browser --%>

是的,有一些特殊的服务器端评论:

<%-- Text not sent to client  --%>

虽然这是有效的:

<%-- <%@ 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" %>

这个不会。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" <%--Inherits="ht_tv1.Default"--%> Inherits="Blank._Default" %>

所以你不能注释掉我99.9995%的时候都想做的事情。