【发布时间】:2014-03-18 01:21:50
【问题描述】:
有没有办法在 asp.net 中隐藏一段代码,以便只有在发生某些事情时才可见?
我有这个,但它不起作用。
<asp:DropDownList ID="drop" runat="server" Width="100" Height="25" BackColor="#CEECF5" CssClass="Selection">
<asp:ListItem Text="Rock" Value="1" />
<asp:ListItem Text="Paper" Value="2" />
<asp:ListItem Text="Scissor" Value="3" />
<asp:ListItem Text="Lizard" Value="4" />
<asp:ListItem Text="Spock" Value="5" />
</asp:DropDownList>
<asp:Button Text="Play Hand" ID ="play" runat="server" BackColor="WhiteSmoke" Width="100" Height="25" CssClass="Button"/>
<asp:View ID="GameResults" ViewStateMode="Disabled">
<br />
<table>
<tr>
<td><asp:Image ID="PlayedHand" runat="server" /></td>
<td><asp:Image ID="RandomHand" runat="Server" /></td>
</tr>
<tr>
<td><asp:Label ID="PlayedLabel" Text="You played ....." runat="server" /></td>
<td><asp:Label ID="RandomLabel" Text="Opponent played ....." runat="server" /></td>
</tr>
</table>
</asp:View>
我正在寻找一种方法,使结果仅在按下按钮并评估游戏时出现。
我知道我可以处理单个元素,但这对 HTML 表格标签没有帮助。所以我更喜欢封装整个对象。
有没有办法隐藏整个内容块?
【问题讨论】:
-
将所有内容包装在 ASP:Literal 控件中,然后将其 visible 属性设置为 false。
-
这不起作用。当我尝试时,我得到“'System.Web.UI.WebControls.Literal' 不允许子控件。”
-
啊,是的,里面有图片和标签。抱歉,没看到。