473,326 Members | 2,104 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,326 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 1354
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.