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.
Add comment May 1, 2006