focusing problem and how to process possible simutanious input?

Posted on 2004-11-04
Last Modified: 2012-05-05
I am going to develop a testing system: when user scanned the badge, the bar code scanner will return a string (ended with a carriage return). Also, user can type in the badge number using keyboard and press "Enter" key. My questions are:
1. How to put focus of the returned string from bar code scanner to my text box area on the page? (focusing problem)
2. Is there a simple way to implement: whenever there is a "return" action, system will begin processing? i.e. either when the user scanned the badge successfully(so the bar code reader will return a string ended with "enter"), or user typed in the number and press "enter" key, system will automatically go to the next step and process the input number in the text box area?  

Thanks a lot!

Question by:heyday2004
    LVL 28

    Assisted Solution

    Hi heyday2004,

    1. for this you have to use javascript method: idoftextbox.focus()
    2. check this site :

    LVL 21

    Assisted Solution

    For 2)

    <asp:textbox id="txtScannedNumber" onKeyDown="javascript:checkkeycode()"></asp:textbox>

    function checkkeycode()
       if (window.event.keycode==13)
    LVL 17

    Accepted Solution

    set focus
    Private Sub SetFocus(ByVal ctrl As Control)
        ' Define the JavaScript function for the specified control.
        Dim focusScript As String = "<script language='javascript'>" & _
          "document.getElementById('" + ctrl.ClientID & _

        ' Add the JavaScript code to the page.
        Page.RegisterStartupScript("FocusScript", focusScript)
    End Sub

    You can now call the custom SetFocus() function from any event handler to change the control focus as needed:


    submit on enter
    MyControl.Attributes.Add("onclick", "javascript:if (event.keyCode == 13) document.Form1.submit();")


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now