views:

1050

answers:

2

one of the fields on my form is a textbox that the user types an id. this is the foreign key to another table so I need to bounce the data against that table before letting them submit. I'd rather not use textchanged as every letter they type may incur another query, focus lost would only show an error or validate when they are already in another field (not sure if it would fire if they just clicked submit).

I would prefer not to force someone's focus to stay in that field, but perhaps that's the best way?

Is there a method to sleep and wait to see if there is another incoming key event within X seconds? if so can I peek to see if it's a letter or number vs a tab or return?

Is there another event I should be hooking that's user friendly?

Should I pull down a copy of that column of the table and real time compare there? (I could handle adding a refresh button to pull a new cache)

+1  A: 

You may want to consider using a timer control for this.

Disable and Enable the control every time the key is pressed, to reset the timeout.

Then when the timer event fires, Disable the control and query the database.

EDIT: I still think your best bet is probably on the Lost Focus event.

John Gietzen
Lost focus event seems to be going ok on my machine. response from the server is lightning fast it seems, so I am not sure what will happen on a user's machine. i'm disabling that field briefly while I bounce it against the database, since disabling the form lost where the user was trying to switch focus to.
Maslow
A: 

Unless that field powers other controls of the form why do you want to interrupt them while filling out the form at all? Why not check for the error on submit?

kscott
I doubt that he want's to interrupt them, but rather add a visual indication that there is an issue. (Like a red asterisk, or similar.)
John Gietzen
I understand, but you can add a red asterisk to the offending field after evaluating the whole form just as easily as after that field is filled out.
kscott
Additionally, if there are a set number of values why use a free form textbox at all? How about a drop down, or if there is too large a set of options a textbox with AJAX suggestions?
kscott
AJAX suggestions in a windows application? I thought AJAX was a web technology?Also we're talking about a warehouse of boxes so this field would be a box number. there are >24 rows, >24 columns, and likely >3 shelves, so that's 24*24*3 possibilities=1152 drop down wouldn't work well there.
Maslow
I'd prefer to go ahead and get validation done while they are in that field or working on another so that submit doesn't have a delay, I'm now buffering/caching valid results for this field to stop trips to the database on already-validated results. There are 7 fields including this one, and the box number could be the same on many of the users' back to back form submissions.
Maslow
Ahh didn't realize it was a windows app, obviously AJAX wouldn't work.Another less elegant selection is just add a button to perform the check, a "this is the box number i want to use, is this ok?" button
kscott