Autofocus to the textboxes... RRS feed

  • Question

  • Hi to all,

    I am using 1.1 with vb coding.. and there is an entry screen to enter the numbers in the 18 tex boxes.. one by one. (maxlenght for the all
    text box =2).

    when the user enters the number into the first textbox (two digit number) the cursor should automatically focus to the next box..

    How to do this...? Its urgent.. P

    Help me as soon as possibile.....

    Thank You...

    • Moved by Riquel_DongModerator Monday, May 4, 2009 7:37 AM ASP.NET issue (From:Visual Basic Express Edition)
    Monday, April 27, 2009 7:28 AM

All replies

  • This seems to work:

    Public Class Form1
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            If TextBox1.TextLength = 2 Then TextBox2.Focus()
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        End Sub
    End Class

    Monday, April 27, 2009 8:30 AM
  • Dont forget to set the autopostback = true for the textbox.

    Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
    Monday, April 27, 2009 8:55 AM
  • Please post ASP.NET development issues to ASP.NET forum .
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 29, 2009 1:42 AM
  • HI to all...

     I found the solution using javascript.... and onkeyup event the solution is as follows,

    <SCRIPT type="text/javascript">
    function SetFocus_t(txt)

      if ("TextBox1") != -1 && txt.value.length==5)
        document.getElementById("<% =TextBox3.ClientID%>").focus();
    function SetFocus_t1(txt)
      if ("TextBox3") != -1 && txt.value.length==8)
        document.getElementById("<% =textbox4.ClientID%>").focus();

    <asp:textbox id="TextBox1" onkeyup="SetFocus_t(this);" tabIndex="2" runat="server" Width="112px"></asp:textbox>

    <asp:textbox id="TextBox3" onkeyup="SetFocus_t1(this);" tabIndex="2" runat="server" Width="112px"></asp:textbox>

    first i would like to thank all ...
    And a small request to all who helped me ...
      This is working fine and I would like to know without using javascript...

       I can't able to do this in the textbox_text changed event....
    Thanks once again. and waiting for ur answers... 

    Wednesday, April 29, 2009 8:42 AM