【问题标题】:Is there a way to comment out markup in an .ASPX page?有没有办法在 .ASPX 页面中注释掉标记?
【发布时间】:2010-09-12 09:24:16
【问题描述】:

有没有办法在.ASPX 页面中注释掉标记,这样它就不会传递给客户?我已经尝试了标准 cmets <!-- --> 但这只是作为评论传递,并且不会阻止控件呈现。

【问题讨论】:

    标签: asp.net markup comments


    【解决方案1】:
    <%--
                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

    【讨论】:

      【解决方案2】:

      奖励答案:Visual Studio 中用于注释掉任何内容的键盘快捷键是 Ctrl-KC 。这适用于许多地方,包括 C#、VB、Javascript 和 aspx 页面;它也适用于 SQL Management Studio 中的 SQL。

      您可以选择要注释掉的文本,也可以将文本放置在要注释掉的块中;例如,将光标放在 GridView 的开始标记内,按 Ctrl-KC,整个内容被注释掉。

      【讨论】:

        【解决方案3】:

        仅供参考 | ctrl + K, C 是 Visual Studio 中的注释快捷方式。 ctrl + K, U uncmets.

        【讨论】:

          【解决方案4】:
          <%-- not rendered to browser --%>
          

          【讨论】:

            【解决方案5】:

            我相信您正在寻找:

            <%-- your markup here --%>
            

            这是一个服务器端注释,不会传递给客户端……但这不是可选的。如果你需要它是可编程的,那么你会想要this answer :-)

            【讨论】:

              【解决方案6】:

              是的,有特殊的服务器端 cmets:

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

              【讨论】:

                【解决方案7】:

                虽然这有效:

                <%-- <%@ 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% 的时间都想做的事情。

                【讨论】:

                  【解决方案8】:

                  另一种假设您要注释掉的不是服务器端代码的方法是......

                  <asp:panel runat="server" visible="false">
                      html here
                  </asp:panel>
                  

                  【讨论】:

                  • 我确实删除了这个答案,因为它不是严格的“注释掉”。然而,乔尔的回答是指我的,所以我暂时取消了它。
                  • asp:PlaceHolder 的作用相同,但设计为不生成任何额外的 HTML。
                  猜你喜欢
                  • 1970-01-01
                  • 2011-08-02
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2020-04-08
                  • 2023-01-31
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多