I'm creating a form in ASP.Net to replicate a paper form (I have no say in the design, I'm tasked with merely recreating it digitally). This form has many questions along the lines of "Answer yes or no. If yes, specify how much". I'm currently handling it by listing the question, and then having two radiobuttons in a group, one saying "yes" and one "no". To make this a little prettier, I've been using Ajax updatepanels that will only display a textbox to hold this yes value if the user selects Yes.
Now I've been able to do this successfully, but each question is its own radiobutton group and has its own panel to update visibility, which means that the way I'm currently doing it there is a lot of redundant code like
Protected Sub rdoShowOriginalEquipment(ByVal sender As Object, ByVal e As System.EventArgs)
If rdoOEYes.Checked = True Then
pnlOriginalEquipment.Visible = True
ElseIf rdoOENo.Checked = True Then
pnlOriginalEquipment.Visible = False
End If
End Sub
And so on for every question that has a yes/no option like that. I have no doubt there is a better way to do this. I was wondering if there is a way I could pass the panel associated with the radiobutton group so I could use a single method in the code that would fire for all radiobutton postbacks, something like (not real code)
Protected Sub showPanel(RadioButtonGroup, panel)
If rdoYes.Checked = True Then
panel.Visible = True
ElseIf rdoNo.Checked = True Then
panel.Visible = False
End If
End Sub
Or is there a better way to handle questions like this? I'm open to a different approach if it would cut down on the amount of redundant code that I'm typing now. I'm using VB, but I know C# so if someone is fluent in that with an answer I'd have no problem interpreting it.
Any help is much appreciated.