Question : 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.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
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

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

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
Page.RegisterStartupScript("SetFocus", _
"<script>document.getElementById('" & txtph.ClientID & _
"').focus();</script>")

         
        Catch ex As Exception

        End Try
    End Sub



Random Solutions  
 
programming4us programming4us