I want validation module to work when the user leaves the textbox or the textbox is out of focus. i.e. when the user input in one textbox and then focus on other textbox for input instantly error message should popup if the previous input is not valid.
Suppose ::
Username :: //txtUsername
Phone :: //txtPhone
here error message should popup instantly for txtName if it is invalid when txtName is out of focus.
I've develop a module for validation but it works when the form is complete,i.e. only at the save time.
#region "Input Validations"
private bool IsClientValid()
{
if (txtUsername.Text == string.Empty || txtUsername.Text == null)
{
MessageBox.Show("User Name is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (txtUsername.Text.Length > 200)
{
MessageBox.Show("User Name cannot be more than 200 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (txtPhone.Text.Length > 20)
{
MessageBox.Show("Phone Number cannot be more than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
#endregion
Manoj BhoirPosted May 21, 2015, 4:26 AM
hadoop hadoopPosted May 21, 2015, 1:47 AM
Nanhe SiddiquePosted May 21, 2015, 1:10 AM
Manoj BhoirPosted May 21, 2015, 1:01 AM
- Enter
- GotFocus
- Leave
- Validating
- Validated
- LostFocus
When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:- Enter
- GotFocus
- LostFocus
- Leave
- Validating
- Validated
If the CausesValidation property is set to false, the Validating and Validated events are suppressed.If the Cancel property of the CancelEventArgs is set to true in the Validating event delegate, all events that would usually occur after the Validating event are suppressed.