Make a panel appear and disappear using a checkbox. And do validation on the controls if visible
Hello. I would like to make a "same as mailing address" section on a form. If the checkbox labeled "Address same as client" is checked then the panel with the textboxes to record address information will disappear and the person can submit the form without filling out the information. However, if that box is not checked the the panel with the textboxes to record address information should be visible and the user should be forced to fill out that information before the form can be submitted. I know how to do validation but not in this situation. Here is the code I have so far.
This is the code for the checkbox:
Mailing Address:<asp:CheckBox ID="chkAddrSameAsClient" runat="server" Text="Address same as client" AutoPostBack="true" OnCheckedChanged="chkAddrSameAsClient_CheckedChanged"/
When the box is checked I thought I could run some code like this to make the panel visible or not visible. This is the chkAddrSameAsClient_CheckedChanged function that is supposed to fire each time the checkbox is clicked on. Or at least this is what was trying to do:
Protected Sub chkAddrSameAsClient_CheckedChanged(sender As Object, e As EventArgs)
Response.Write("same address checked: " & chkAddrSameAsClient.Checked)
If (chkAddrSameAsClient.Checked = "True") Then
pnlGuarantorAddress.Visible = True
pnlGuarantorAddress.Visible = False
When I added this the panel would appear and disappear each time the checkbox was clicked. It didn't matter what the value was. I want the panel's visibility to be false if the checkbox value is "True". And vise versa if the checkbox value is "False" . But for some reason that seems to be ignored and the panel appears and disappears on clicks no matter the value of the checkbox. So I also added some code that I thought would check the value of the checkbox each time I did a autopostback. But that didn't work either but here it is.
If (chkAddrSameAsClient.Text = "False") Then pnlGuarantorAddress.Visible = True End If