Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have 2 text boxes in a form.

 

areacode and phone

 

i want to make it so when 3 digits are entered in the area code, it sets the focus to the phone field.

 

is there a method to setfocus in asp.net? or do i have to write some javascript?

Posted

here is a piece of code to set the focus from asp.net. but this code wont help you in this case since u will need to go to the server. thats why u should use the focus() javascript method. The code im providing actually writes javascript to the client from the server. Anyways here is the code:

 

method call:

setFocus(TextBox1.ClientID)

 

method declaration:

Private Sub setFocus(ByVal ctrlClientID As String)

RegisterStartupScript("focus", "<script language=""JavaScript"">" & vbCrLf & _

vbTab & "Form1." & ctrlClientID & ".focus();" & _

vbCrLf & vbTab & "Form1." & ctrlClientID & ".select();" &

vbCrLf & "<" & "/script>")

End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...