Pregunta

I have a textbox inside a update panel:

<asp:TextBox ID="txtInsert" 
             runat="server" Font-Size="Large" MaxLength="13" 
             Width="150px" onkeyup="doPostBack(this);" AutoPostBack="True"
             OnTextChanged="txtInsert_TextChanged"></asp:TextBox>

and this textbox should get the value from scanning a barcode. All the bar codes have 13 digits. in the txtInsert_TextChanged method i check if the value scanned in inside a table and display a message and delete the textbox value.

The problem is that sometimes it only reads 1 character or 4 characters, sometimes i have 13 digits but they are made out of 2 barcodes combined.

Basically i think i have to somehow increase the time for key up since it only reads part of the bar code and then combines it with a second bar code read...

and by the way : the doPostBack(this) method is here:

<script type="text/javascript">
    function doPostBack(o) {
        __doPostBack(o.id, '');
    }
</script>

Any ideas ?

PS: the scanner doesnt trow an ENTER at the end...

¿Fue útil?

Solución

Since your bar-code reader is on the client computer, when you call __dopostback the browser loads the same page again, and during this time, all the keyboard events simulated by the bar-code reader aren't transmitted to the textbox.

So you need to do the postback only when you have 13 characters in your textbox.

You can modify your javascript to do something like this: (not actual javascript)

if (this.value.length == 13) __dopostback(this);

Otros consejos

The textchanged event will fire when the text property is changed, so a single character change will trigger the event.

I'd recommend checking how you're populating the textbox and if you can switch to putting the whole barcode number into the textbox in one go so you only trigger the event once.

Failing that inside the event handler you could just check the size of the text and only deal with it when it's the right number of characters.

The scanner will probably throw an Enter after it read the entire code. Put a submit button next to it or capture key 13.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top