• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

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
0
6784
Asked:
6784
  • 4
  • 2
  • 2
  • +2
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now