在ASP.Net(4.5.2)中,我嵌套了<span>
元素,其中父元素被设置为服务器端控件...
<p>
This is the start of the text
<span runat="server" visible="<%#someCode%>">
This is some more Text
<span class="myClass">with some other text inside</span>
And a bit more after
</span>
</p>
(注意,它包含在<asp:Repeater>
中)
ASP.Net似乎无法解决这个问题,并且似乎假定内部</span>
是外部元素的闭包。意思是当visible="false"
时,它会像这样呈现...
<p>
This is the start of the text
And a bit more after
</span>
</p>
我无法将<span>
转换为<div>
或<section>
,因为它必须存在于<p>
元素中(这意味着子元素不能是块)。>
有什么办法可以解决这个问题?
答案 0 :(得分:1)
然后确定(评论太多)。
或者使用Label
:
<p>
This is the start of the text
<asp:Label ID="Label1" runat="server" Visible="false" Text="This is some more Text">
<span class="myClass">with some other text inside</span>
And a bit more after
</asp:Label>
</p>
甚至:
<p>
This is the start of the text
<asp:Label ID="Label1" runat="server" Visible="true" Text="This is some more Text<span class='myClass'>with some other text inside</span>And a bit more after">
</asp:Label>
</p>
答案 1 :(得分:0)
结果很简单...使内部<span>
也成为服务器端控件...
<p>
This is the start of the text
<span runat="server" visible="<%#someCode%>">
This is some more Text
<span runat="server" class="myClass">with some other text inside</span>
And a bit more after
</span>
</p>
这会导致...
<p>
This is the start of the text
</p>