【问题标题】:I commented out HTML code, but the control inside it is not disabled我注释掉了 HTML 代码,但是里面的控件没有被禁用
【发布时间】:2011-08-02 13:59:49
【问题描述】:

我用 HTML 代码注释掉了我的表格。尽管表格确实被删除了,但其中的控件似乎仍然存在。

<div>
    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="#0066CC"></asp:Label>
    <!--
    <table>
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="#0066CC"></asp:Label>
            </td>
        </tr>
    </table>
    -->
</div>

当我运行我的应用程序时,Visual Studio 给我一个错误:

ID 'Label1' 已被另一个 rcontrol 使用。

我不知道为什么 Visual Studio 仍然检查我的 HTML 的注释掉部分内的控件。有人对此事有任何线索吗?提前致谢!

【问题讨论】:

  • 想必如果你更改任一标签的 ID 都不会出错?
  • 是的,如果我将任一标签的ID从Label1更改为Label2,则不会发生错误。

标签: .net asp.net html comments


【解决方案1】:

那是 html 注释,而不是 asp.net 服务器端注释。你应该使用&lt;% -- code --%&gt;

<%--
    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”) %>     
--%>

看看Scott Guthrie's post

【讨论】:

  • 感谢您的回答!这很有帮助!
猜你喜欢
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 1970-01-01
  • 2016-04-25
  • 2020-04-30
  • 2014-02-12
  • 2011-08-02
  • 2013-03-28
相关资源
最近更新 更多