0

我想在RadioButtonList的OnSelectedIndexChanged事件上显示/隐藏Div标签(其中包含其他asp.net控件)。当Div标签可见时,Div标签中的Asp.net控件不可见?

问题:当我显示Div标签时,Div标签中的控件不可见。见下面

.aspx页面中我的代码

<asp:RadioButtonList ID="rblTesting" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rblTesting_SelectedIndexChanged"> 
    <asp:ListItem Text="Show" Selected="True" Value="0"></asp:ListItem> 
    <asp:ListItem Text="Hide" Value="1"></asp:ListItem> 
</asp:RadioButtonList> 
<div id="divName" runat="server"> 
    <asp:Label ID="lblFirstName" runat="server" Text="James"></asp:Label> 
    <asp:Label ID="lblLastName" runat="server" Text="Anderson"></asp:Label> 
</div> 

.aspx.cs

Protected Sub rblTesting_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
     If rblTesting.SelectedIndex = 0 Then 
      divName.Visible = True 
      'lblFirstName and lblLastName labels are not visible? 
     Else 
      divName.Visible = False 
     End If 
    End Sub 

我可以显示/隐藏选定的指数变化事件在div个人控制。但是,我的问题是为什么我的控件在Div可见时不可见。

回答

0

C#代码是

rblTesting.Visible = false; 
rblTesting.Visible = true; 

的第一部分是一个HTML标签或ASP.NET控制的id名称。如果使用html标签,则必须将属性runat =“server”添加到html标签