【问题标题】:Using asp:Literal text in html attributes在 html 属性中使用 asp:Literal text
【发布时间】:2017-07-10 16:21:33
【问题描述】:

快速提问。有没有办法在 HTML 属性中使用 asp:Literal text?

例子

<asp:Literal Text="hidden" runat="server" ID="ClassTag"></asp:Literal>

<tr class='<%= ClassTag %>' run="server" > </tr>

我正在研究针对上下文的中继器表行折叠问题 (asp:repeater collapsing table rows) 的整体解决方案,这可能是我坚持的最后一件事。

请告诉我。谢谢!

【问题讨论】:

  • 如果 tr 没有在服务器端运行,是的,你可以。
  • 为什么tr 仍然在服务器上运行?它没有ID,所以它是不可寻址的(除了步行控制集合,但是...... ewww)。如果您还将.Text 属性添加到ClassTag,则删除它,您所拥有的应该可以正常工作。

标签: c# asp.net asp-literal


【解决方案1】:

不是真的,但您只是想通过代码在 TR 上设置类吗?

在这种情况下,在 ASP.NET 中编写以下代码:

<tr runat="server" ID="CustomRow">

并在代码隐藏中通过 Attributes 集合设置类:

CustomRow.Attributes.Add("class", "[desired css class]");

【讨论】:

  • 我实际上最终得到了一个非常接近这个的解决方案。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
  • 2011-11-07
  • 2012-06-06
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
相关资源
最近更新 更多