Link to home
Start Free TrialLog in
Avatar of Bran-Damage
Bran-DamageFlag for United States of America

asked on

Set focus to a text box on a web page after textchanged event...

I have an aspx page that has text boxes.  On one of my text boxes I have a changedText event.

After the changed text event the cursur goes to an undesirable location.

I tried to do a me.txtph.focus() but that did not work.

What I am looking to do is either go to me.txtph or put the cursur when they hit tab to the next tab order or when they click on a different field, keep the cursur there.

Any ideas would be helpful.

I have attached my changed text event code.
Protected Sub txtstate_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Try

            If Me.txtstate.Text = "AE" Or Me.txtstate.Text = "AA" Or Me.txtstate.Text = "AP" Then

                If TxtdelDoc.Text <> "" And TxtFromCountry.Text <> "" And txtcountry.Text <> "" Then
                    btnInternational.Enabled = True
                End If

            Else
                btnInternational.Enabled = False
            End If
            Me.txtph.Focus()

        Catch ex As Exception

        End Try
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Robb Hill
Robb Hill
Flag of United States of America image

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
That was jscript solution to ....but you can try this too I think.

use Page.SetFocus method with control's ID as a parameter
SOLUTION
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
Avatar of Bran-Damage

ASKER

Both of these solutions work, but my main issue, I found out, was not actually with the java script.  There was an auto postback occurring that was causing the set focus to go to another area than desired.

I modified this, used your java script... BOOM, worked like a charm