【问题标题】:"The server tag is not well formed." What's wrong?“服务器标签格式不正确。”怎么了?
【发布时间】:2013-06-17 01:48:00
【问题描述】:

我收到以下解析器错误消息。我该如何解决这个问题?

服务器标签格式不正确。

代码:

<a href="#" class="mySprite id<%# ((int)DataBinder.Eval(Container,"ItemIndex")) % 6 + 1%>">

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    首先,你的锚点是客户端,你应该给它添加一个runat="server"的属性。其次,尝试如下使用它。

    <a href="#" runat="server" id="mySprite1" 
    class='<%# "mySprite id" + ((int)DataBinder.Eval(Container,"ItemIndex")) % 6 + 1 %>'>
    

    【讨论】:

    • 我需要给单引号什么的吗?
    • 您不需要runat="server",只要您不在数据绑定事件(或标签的关联控件属性)上使用 html 控件!
    • @Andreas::是的,我知道..thnx...@Zain :: 缺少单引号..现在已解决..thnx
    【解决方案2】:

    查看表达式的差异可能会有所帮助:http://blogs.msdn.com/b/dancre/archive/2007/02/13/the-difference-between-lt-and-lt-in-asp-net.aspx

    runat="server" 仅用于数据绑定。

    因此,请改用&lt;%= %&gt; 语法。还要确保您的引号没有混淆,因此请使用' 表示外层," 表示内层。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-15
      • 2012-12-14
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      相关资源
      最近更新 更多