Archive for May, 2006

Winform Validation: Keypress vs TextChanged

Suppose I want to run a validation routine when the text changed, one could have it call an validateField either by keypress (keydown, keyup, etc) or TextChanged.

private void validateField(){

if (HasPeriod(this._myfield)

{

     this._myFormErrorProvider.SetError(this._myfield, "Field must not have periods.");

}

else

{

this._myFormErrorProvider.SetError(this._myfield, "");}}

The routine uses a simple string search using val.IndexOf() to check if the string contains a period. What I have notice is that if I do this in a keypress event and I press a period key. The period won't be notice until I press another key. With a TextChanged event, the period is noticed right away.

Advertisements

May 1, 2006 at 8:56 pm Leave a comment


Calendar

May 2006
M T W T F S S
« Apr   Jun »
1234567
891011121314
15161718192021
22232425262728
293031  

Posts by Month

Posts by Category