Link to home
Start Free TrialLog in
Avatar of cbdrako99
cbdrako99Flag for United States of America

asked on

How to conditionally copy the results of one textbox to another textbox depending on the status of a checkbox.

Hello Experts,

I am creating a webform using VB.net to collect information and then email the results to a single recipient. The form asks for patient information and responsible party information.  Many times this is the same person.  If the checkbox is = true then fill in the responbile party fields with the text of the patient fields.  
Thanks in advance for your help.
Avatar of gangwisch
gangwisch

you need to do a checkbox1_oncheckchanged event on your code behind page
Avatar of cbdrako99

ASKER

I already have that.  Here's my attempt at the code which doesn't work.

    Protected Sub chkRPSame_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRPSame.CheckedChanged
        If chkRPSame.Checked = True Then
            txtRPFirstName.Text = txtPatFirstName
        End If
    End Sub

Any ideas?
Sorry. The code is actually...

    Protected Sub chkRPSame_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRPSame.CheckedChanged
        If chkRPSame.Checked = True Then
            txtRPFirstName.Text = txtPatFirstName.Text
        End If
    End Sub

But it does't do a thing.
That code should work but only after you have typed in the value in the textbox and then checked the checkbox.  It won't work if the checkbox is checked prior to putting a value in the checkbox as the event will never fire.
ASKER CERTIFIED SOLUTION
Avatar of maralans
maralans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you need something more like this:

Private Sub txtPatFirstName.Text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPatFirstName.Text.TextChanged
        If chkRPSame.Checked = True Then
            txtRPFirstName.Text = txtPatFirstName.Text
        Else
            txtRPFirstName.Text = ""
        End If
    End Sub
maralans,
Your'e right. I wasn't giving the control a chance to fire.  This was clearly a case of not seeing the forest for the trees.  Thanks!