在asp.net中隐藏内容

时间:2014-03-17 17:14:34

标签: c# asp.net

有没有办法在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表格标签没有帮助。所以我更希望整个对象被封装。

有没有办法隐藏整个内容块?

1 个答案:

答案 0 :(得分:2)

在GameResults视图中,将所有内容包装在div中:

<div id="divResults" runat="server" hidden="true">

在后面的代码中,转到按钮点击事件并添加条件并设置可见性。

(伪码:)

If (game is evaluated) then divResults.hidden= false