I made a small application in VB.NET that allows user to scan a bunch of barcodes and save them in the database.

Application works both for the regular computer browser and handheld pocket PC.

Barcode can be either scanned into upc text field and automatically submitted to db or numbers can be manually added into upc text field and pressing Enter will add it to db.

There are also two buttons on the page. One button "Clear" is to clear upc field in case user started a manual input and didn't like it. Second button "Exit" logs out a user.

There is a problem that I don't know how to resolve.

User should just scan a barcode and it will be automatically added to db without pressing any Submit button so user can go through a lot of barcodes fast. In order to achieve this, upc text field has AutoPostBack property set to True.

Then in the Page_Load event if len(upc.text)>0, then data from upc.text gets submitted to db and upc.text gets empty again. If len(upc.text)=0, nothing happens.

So it works fine in case of a handheld. It scans and sets upc.text to empty string. So if I scan and press Exit button after that, I just exit without a problem.

But there is a bug if I input a upc number manually and then press an Exit button for some reason. Pressing a button causes the page to reload and number gets submitted to the database anyway though I just wanted to exit. In fact, if there is any data in the upc field, any action, pressing Enter, pressing the button, clicking with mouse on the screen, causes that data to be submitted to db in the page_load event.

How can I avoid this situation if I still want items to be submitted automatically without pressing any button while scanning?