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標籤