473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Selecting Another Textbox

What i am doing is pretty simple. I am writing a simple control that you
probably have seen on many websites. You have a phone number field ( 3
Textboxes ) if the size of the textbox text is = 3 move to the second text
box. My problem is: How do i tell my app to select the second text box?

Here is an example on what I have so far:
Private Sub txtPhone1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtPhone1.TextChanged
If Len(txtPhone1.Text) = 3 Then
HELP!!!
End If
End Sub
Jul 22 '05 #1
3 1355
Call the focus method of the textbox you want selected:

TextBox2.Focus()

Jul 22 '05 #2
You should probably do this on the client-side, using JavaScript, without a post-back.

If you really want to handle it in a post-back event, then you should emit script to the client to focus your textbox.

Inline:
Private Sub txtPhone1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtPhone1.TextChanged
If Len(txtPhone1.Text) = 3 Then
' Please forgive me that I haven't done VB.NET coding in quite a while....

Page.RegisterStartupScript( _
"txtPhone1AutoTab", _ ' name the script, uniquely
String.Concat( _ ' provide the script as a string
"<script language='JavaScript' name='txtPhone1AutoTab'>", vbCrLf, _
"document.getElementsByName(", txtPhone2.ClientID, ")[0].focus();", vbCrLf , _
"</script>"))

' Is there a literal-token in VB.NET??

' Just note that you'd probably be better off adding the registration code in the OnPreRender method and just setting a variable
here that will cause the script to be registered if the controls are visible at the time of rendering.
End If
End Sub
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"DOTNETGUY" <DO*******@discussions.microsoft.com> wrote in message news:A9**********************************@microsof t.com... What i am doing is pretty simple. I am writing a simple control that you
probably have seen on many websites. You have a phone number field ( 3
Textboxes ) if the size of the textbox text is = 3 move to the second text
box. My problem is: How do i tell my app to select the second text box?

Here is an example on what I have so far:
Private Sub txtPhone1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtPhone1.TextChanged
If Len(txtPhone1.Text) = 3 Then
HELP!!!
End If
End Sub

Jul 22 '05 #3

Hi there,

This is not going to work server side. You have to do it client side using
Javascript to check the size of the text in the box. I am not sure if ASP.NET
will cause a postback after every key stroke. I think it does a postback
after the box looses focus. Never the less, you don't want postbacks back and
forth every time someone types something, do you?

Good luck!

--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray
"DOTNETGUY" wrote:
What i am doing is pretty simple. I am writing a simple control that you
probably have seen on many websites. You have a phone number field ( 3
Textboxes ) if the size of the textbox text is = 3 move to the second text
box. My problem is: How do i tell my app to select the second text box?

Here is an example on what I have so far:
Private Sub txtPhone1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtPhone1.TextChanged
If Len(txtPhone1.Text) = 3 Then
HELP!!!
End If
End Sub

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: melanieab | last post by:
Hi, I need to write something so that when a textbox is entered (this is for a touchscreen), all the text in that textbox is selected (highlighted) and new keystrokes replace the old text. Help!...
3
by: Strange Cat | last post by:
Hi everyone Is it possible to select the contents in an aspnet textbox? (Like the old textbox selectstart and so on properties) Thanx in advance
0
by: Steven W | last post by:
I'm trying to setup a datagrid in a custom control where I can select the row with the Select column hidden and have it call the "SelectIndexChanged" event. In the "SelectIndexChanged" I just want...
1
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed...
5
by: marfi95 | last post by:
I'm very confused. I'm trying to automatically select the text when my textbox gets the focus. This is typically when the user has clicked the mouse in the field. This is the code I have in...
4
by: rcoco | last post by:
I want to select one Row from a datagrid so I create a textBbox(txtname) and Button for the user to write the name in textBox and By the click of the button it select the corresponding row. But...
2
by: Abubakar | last post by:
Hi, In a normal Windows.Forms.TextBox control, I want to be able to select a text (ie highlight, this is by default possible) and than be able to drag that text through my mouse pointer to another...
2
by: JJ | last post by:
I have a textbox that is used to insert some html code. I want to highlight errors in the code, possibly by selecting the text. Is it possible to highlight/select areas of a textbox...
2
by: billa856 | last post by:
Hi, I have one projrct in MS Access. I have one form in which there is one Combobx(PalletNo_combo) and one Textbox(ShippedQuantity). Now when I select an item from Combobox then it will...
3
by: Shawn | last post by:
I'm trying to go through a large number of logically named textboxes using a loop and cannot figure out how short of explicitly referencing every single one.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.