best way to make text2.text = text1.text as text1. looses focus

what would be the best way to make text2.text = text1.text as text1. looses focus

thanks
6784Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

planoczCommented:
Private Sub text2.text _LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles text2.text .LostFocus
text1.text = text2.text
    End Sub

or

   Private Sub  text2.text _TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles  text2.text .TextChanged
text1.text = text2.text
    End Sub
0
rdrunnerCommented:
Just create an eventprocedure for the lostfocus event in it use this code...

text2.text = text1.text

0
rdrunnerCommented:
Just like planocz suggest but the other way around ;)
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

planoczCommented:
Yep,I did type that backwords :)
0
6784Author Commented:
sorry, I should have asked this question in ASP.NET.
This code doesn't work.

 Private Sub txtNamePart1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNamePart1.TextChanged

        txtLegalName1.Text.TextChange ******** TextChange is not a member of "String"
        txtSOrtName.Text = txtLegalName1.Text

    End Sub
0
karthikeyanTPCommented:


>>>txtLegalName1.Text.TextChange ******** TextChange is not a member of "String"


what is this statement and what are you trying to do? This statement does not look like a full statement

0
6784Author Commented:
>>>txtLegalName1.Text.TextChange ******** TextChange is not a member of "String"
Never mind, I wrote it down wrong.

ASP.NET app. As soon as a name is entered in one text box I need it to apear in another.
0
ifucdseemeCommented:
If you are going to post back the form with a button you can use this.

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
     Me.TextBox2.Text = Me.TextBox1.Text
End Sub

If you want TextBox2 to populate without posting back to the server you will need to use javascript.

Here is an example:

'Place this code in the webForm Page Load event, you can change the the onKeyUp to any valid javascript event. ie(onBlur, onChange, etc..)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     Me.TextBox1.Attributes.Add("onKeyUp", "PopulateTextBox2()")
End Sub

Place this code in the <Head> section of the html
<script language="JavaScript">
     function PopulateTextBox2(){
          document.Form1.TextBox2.value=document.Form1.TextBox1.value;
     }
</script>

Now when you type anything in TextBox1 it will also be displayed in TextBox2
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
6784Author Commented:
ifucdseeme,

I found this code on the net yesterday

 Dim js As String
        js = "javascript:" & Page.GetPostBackEventReference(Me, "@@@@@buttonPostBack") & ";"
        txtNamePart1.Attributes.Add("onchange", js)  (this is placed in Page_Load Event)

this just activates the TextChangeEvent of this parocedure

 Private Sub txtNamePart1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNamePart1.TextChanged

        With txtNamePart1
            .Text = Trim(UCase(.Text))
            txtSOrtName.Text = Left(LettersOnly(.Text), 10)
            txtLegalName1.Text = .Text
        End With

I am trying to add another textbox to your code

 Me.TextBox1.Attributes.Add("onKeyUp", "PopulateTextBox2()")

Me.TextBox1.Attributes.Add("onKeyUp", "PopulateTextBox3()")

<script language=JavaScript> function PopulateTextBox2(){  
        document.Form1.TextBox2.value=document.Form1.TextBox1.value;
        }</script>

<script language=JavaScript> function PopulateTextBox3(){
         document.Form1.TextBox3.value=document.Form1.TextBox1.value;
         }</script>

when I run this, textbox2 doesn't populate but textbox3 does???
Now, I am going to try to add formatting. Wonder where it would work the best. In the html or code page?


    End Sub
0
6784Author Commented:
I am able to have two textboxs populate. Still working on formating
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.