Preventing AutoSubmit when using Barcode Reader with Page

Posted on 2007-10-10
Last Modified: 2009-02-11
I am building an inventory entry page in for my store. I want to allow some data to be entered from a Bar code reader.  Using the bar code scanner with my current code works, it enters the data to the field correctly. Currently, however the action of scanning the item is equivalent to typing the data and pressing the enter key. This triggers the submit event on the page.  How do i prevent this from happening? Thanks in advance for the help

Relevant control code:
Line where barcode would be scanned...
<asp:TextBox ID="C_Alias" TextMode="SingleLine" runat="server" Width="99%" Text=""></asp:TextBox>

Submit button...
 <asp:Button ID="C_Submit" runat="server" Text="Add Item" OnClick="C_Submit_Click"></asp:Button>

Submit Function Header...
    Protected Sub C_Type_Change(ByVal sender As Object, _
            ByVal e As System.EventArgs)
Question by:apocalypse910
    LVL 9

    Expert Comment

    You have a couple of solutions you can use:

    1) Capture the "Enter" key with Javascript and disable it.  Often the barcode scanner simulates "Enter" when the barcode is read fully.
    2) Set the barcode scanner to not hit "Enter" as the suffix.  Some barcode scanners can be set to do this... others cannot.

    I've used both of these techniques with success.

    Hope that helps.
    LVL 9

    Accepted Solution

    The javascript to catch the "Enter' key is as follows:

     function handleKeyPress(evt) {
      var nbr = (window.event)?event.keyCode:evt.which;
    your code here

     document.onkeydown= handleKeyPress

    Look up an ASCII key code table on Google to find more info on it.

    Author Comment

    That is Perfect.. Thank you very much for your help.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    733 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

    18 Experts available now in Live!

    Get 1:1 Help Now