0

在 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>

(注意,这包含在 a 中<asp:Repeater>

似乎 ASP.Net 无法解决这个问题,并且似乎假设内部</span>是外部元素的闭包。这意味着当visible="false"它会呈现这样的......

<p>
  This is the start of the text
    And a bit more after
  </span>
</p>

我不能转换<span>为 a<div><section>因为它必须存在于一个<p>元素中(这意味着子元素不能是块)。

有没有办法解决这个问题?

4

2 回答 2

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>
于 2019-06-06T13:24:41.653 回答
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>
于 2019-06-06T12:39:48.100 回答