【问题标题】:HTML comments in "file.ascx" does not behave like comments“file.ascx”中的 HTML 注释与注释不同
【发布时间】:2026-01-09 20:25:01
【问题描述】:

为什么注释控件仍然搜索它的 tagName...有什么意义...我的意思是,它在 cmets 中,甚至不应该在代码中 EXIST。这就是 cmets 的用途,您应该能够使该部分代码对编译器不可见。这对我来说没有意义。谁能告诉我这是怎么回事?

编辑:


我被要求展示它是什么类型的 cmets,所以我将发布所有控件。

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="MandatMobile.Controls.Menu"  %>


<!-- THIS MENU IS NOT OK


<div id="divi" style="float: left; position:absolute; left:-60px; top:120px;" >
    <asp:Menu ID="bootMenu" 
    runat="server" 
    Orientation="Vertical" 
    StaticDisplayLevels="1"
    StaticEnableDefaultPopOutImage="False"
    OnMenuItemClick="BootMenu_MenuItemClick" 
    MaximumDynamicDisplayLevels="10" 
    EnableViewState="false"
    CssClass="nav navbar-fix-top" 
    DynamicMenuStyle-CssClass="dropdown-menu" 
    IncludeStyleBlock="false" 
    SkipLinkText=""
    RenderingMode="List">

      <Items>
        <asp:MenuItem  Text="" ImageUrl="~/Img/Hamberger.png" ToolTip="Menu" Value="openMenu">  
       </asp:MenuItem>
    </Items>
</asp:Menu>
</div>

-->

<div id='cont' style="position:absolute;"  >

 <% if (Convert.ToInt32(Session["Level"]) == 3)
    { %>
    <input type="button" id="btnAjax" onclick="$(document).ready(function() { $('#cont').load('Controls/contentAdmin.html');});"  style="float: left; position:absolute; width:40px; height:40px; left:10px;  background-image:url(../Img/Hamberger.png);" />

<%}
  else if (Convert.ToInt32(Session["Level"]) == 2)
  { %>

   <input type="button" id="btnAjaxNormal"  onclick="$(document).ready(function() { $('#cont').load('Controls/contentNormal.html');});"  style="float: left; position:absolute; width:40px; height:40px; left:10px;  background-image:url(../Img/Hamberger.png);" />
  <% } %>

【问题讨论】:

  • 嗯...你评论了什么?你做了什么样的评论?
  • @DanielCook 这是代码
  • 这可能不是你想要的那种评论。尝试使用 ASP.Net 评论 &lt;%-- ... --%&gt; 而不是 HTML 评论 &lt;!-- ... --&gt;

标签: html asp.net comments ascx


【解决方案1】:

感谢丹尼尔·库克。使用 ASP.net cmets 而不是 HTML cmets 解决了这个问题。

使用:

<%--  Comments   --%>

而不是:

<!--  Comments   -->

【讨论】:

    最近更新 更多