• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Radio button in ASP .net wont hide textboxes and labels without hitting submit

GoingUp

Lifer
I have a registration page and I have a radio button for either customer or employee. Employee has additional fields that need to be shown and should be hidden when the customer is registering.

The problem that I have is that my original code works, but it will only work when the submit button is clicked. It wont work when I click the different radio buttons. I have to first click a radio button THEN hit submit or the changes wont show. Basically, how can I have the page automatically change without having to hit the submit button?

Here is the code I have so far.

Private Sub person_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles person.SelectedIndexChanged
If person.SelectedValue.Equals("Customer") Then
Label11.Visible = False
Label12.Visible = False
Label13.Visible = False
Label14.Visible = False
txtSoc.Visible = False
txtPayRate.Visible = False
txtPayType.Visible = False
txtStartDate.Visible = False
Label3.Text = "Company"

ElseIf person.SelectedValue.Equals("Employee") Then
Label11.Visible = True
Label12.Visible = True
Label13.Visible = True
Label14.Visible = True
txtSoc.Visible = True
txtPayRate.Visible = True
txtPayType.Visible = True
txtStartDate.Visible = True
Label3.Text = "Position"

End If
End Sub
 
You're going to have to use javascript for this if you want it to happen without a round trip to the server. If you are ok with it posting back automatically as long as they don't need to hit the submit button, you can try the autopostback property. However, you need to be careful to make sure you are only handling the button click event and not any postback for that.
 
Back
Top