I've been developing a web app that accepts input from a barcode scanner. I need to pass scanned barcodes (GS1-128) from client-side to server-side. By standard, GS1-128 may contain one or several group separator <GS> characters (characters with ASCII code 29). Thus, "123<GS>45", "12<GS>345" are DIFFERENT inputs. I have a textbox and a submit button to get the input. For some reason, ASP.NET does not include non-printable characters in the postback and in both cases I receive "12345" instead.
Is there any way to overcome this issue?
P.S. When I'm using a WinForm (for testing) everything is OK and I get the character, but with ASP.NET this doesn't work.
After some digging up I've found out that most barcode scanners actually transmit a series of keystrokes as if they were from the keyboard. As this happens, the <GS> symbol is transmitted as two keystrokes CTRL+] with keycodes values of 17 and 229 correspondingly.
Since it has no printable representation, the Textbox I was using for the input simply ignored it.
What I ended up with was this keyDown event handler placed on the textbox. It simply substitutes '^]' with '|'.
On the server side I simply change it back:
Everything works so far. I wonder if there's a better way to handle the problem though.