我正试图在RadioButtonList OnSelectedIndexChanged事件中显示/隐藏Div标签(其中包含其他asp.net控件)。
问题:当我显示Div标签时,Div标签中的控件不可见。请参阅下面的代码
.aspx page
<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 :(得分:0)
C#代码是
rblTesting.Visible = false;
rblTesting.Visible = true;
第1部分是html标记或ASP.NET控件的id名称。如果使用html标记,则必须将属性runat =“server”添加到html标记