Reputation: 1203
I am trying to unhide a group of radio buttons if the checkbox above it is checked and hide them when checkbox isn't checked. I had a previous version of this, in the same application, and it works just fine [radio button opens checkboxes instead] under Working one. When MinorCheck
is selected the radio buttons don't become visible. No errors show, nothing happens. Why is this?
I have looked at other comments how Visible = "false" stops it and so forth. however, it is clear that visible="false" at the start isn't an issue for my first block of coding.
one reference I have used: ASP.NET CheckBox does not fire CheckedChanged event when unchecking
Working one:
HTML
<td class="LeftAlign" width="24%">
<font class="Blackfont" size="1">
<B> Union Affiliated?
</B>
</font>
<font class="WeOrangefont" size="1">
•
</font>
</td>
<td width="10%">
<asp:RadioButtonList ID="rblclass" runat="server" AutoPostBack="True" class="Bluefont" size="1" font-Bold="True" font-Size="8pt" >
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList>
</td>
<td></td>
</tr>
</table>
VB.NET
Protected Sub rblclass_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblclass.SelectedIndexChanged
If (rblclass.SelectedValue = "Y") Then
Register.Focus()
union1.Visible = True
union2.Visible = True
union3.Visible = True
LocalLbl.Visible = True
Reqimage.Visible = True
Else
Register.Focus()
union1.Visible = False
union2.Visible = False
union3.Visible = False
LocalLbl.Visible = False
Reqimage.Visible = False
End If
End Sub
Other part of coding that doesn't work even though it is very similar:
<tr>
<td class="LeftAlign" colspan="2">
<font class="Blackfont" size="1">
<asp:CheckBox ID="MinorCheck" runat="server" NAME="BUSINESSCLASSIFICATION"
class="ownerClass" value="000" checked = "false" TabIndex="32"/>
<asp:HyperLink ID="HyperLink2" runat="server" TABSTOP = "-1" onClick="OpenWindow('Images/Supp.html', 'Min Business Concern',600, 300, 'no')" font-Underline="True" ForeColor="#666666" >Minority Business Concern</asp:HyperLink>
</font>
</td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="RadioButtonBClass" runat="server" AutoPostBack="True"
class="Bluefont" size="1" font-Bold="True" font-Size="8pt" visible = "false">
<asp:ListItem Value="Y" >African-American male</asp:ListItem>
<asp:ListItem Value="N">African-American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American female</asp:ListItem>
<asp:ListItem Value="N">Native American male</asp:ListItem>
<asp:ListItem Value="N">Native American female</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
VB.NET
Protected Sub MinorCheck_CheckedChanged(sender As Object, e As EventArgs) Handles MinorCheck.CheckedChanged
If (MinorCheck.Checked = true) Then
RadioButtonBClass.Visible = True
NonMinorCheck.Checked = false
Else
RadioButtonBClass.Visible = False
End If
End Sub
Upvotes: 0
Views: 119
Reputation: 1414
Your checkbox is missing the AutotPostBack=True
. Without it, the CheckedChanged
event will not fire until some other control performs a PostBack
.
Upvotes: 1
Reputation: 1258
It is confusing but when you use the property Visible in ASP controls, actually don't create the object at all, so if you tried to change to Visible true is not going to work, what I personally use is a trick with a CSS Class, I am going to copy the code I made for your case:
<style>
.CSSHiden {
display: none;
}
</style>
Note: I set Autopostback=true on the Checkbox Minor Check
<asp:CheckBox ID="MinorCheck" runat="server" NAME="BUSINESSCLASSIFICATION"
class="ownerClass" value="000" TabIndex="32" OnCheckedChanged="MinorCheck_CheckedChanged" AutoPostBack="True"/>
<asp:HyperLink ID="HyperLink2" runat="server" TABSTOP = "-1" onClick="OpenWindow('Images/Supp.html', 'Min Business Concern',600, 300, 'no')" font-Underline="True" ForeColor="#666666" >Minority Business Concern</asp:HyperLink>
<asp:RadioButtonList ID="RadioButtonBClass" runat="server" AutoPostBack="True" class="Bluefont" size="1" font-Bold="True" font-Size="8pt" CssClass="CSSHiden">
<asp:ListItem Value="Y" >African-American male</asp:ListItem>
<asp:ListItem Value="N">African-American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Indian American female</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American male</asp:ListItem>
<asp:ListItem Value="N">Asian-Pacific American female</asp:ListItem>
<asp:ListItem Value="N">Native American male</asp:ListItem>
<asp:ListItem Value="N">Native American female</asp:ListItem>
</asp:RadioButtonList>
And the code I used c#, but is very simple to change to VB.net
protected void MinorCheck_CheckedChanged(object sender, EventArgs e)
{
if (MinorCheck.Checked == true)
RadioButtonBClass.CssClass = "";
else
RadioButtonBClass.CssClass = "CSSHiden";
}
Upvotes: 1