I am developing a Windows Form Application which has lots of Forms and each Form has several controls. In order to implement Validation I have to implement "Validating" event for each controls as following:
private void txtSalary_Validating(object sender, CancelEventArgs e)
{
if (txtSalary.Text.Trim() == String.Empty)
{
errorProvider1.SetError(txtSalary, "Salary is Required");
e.Cancel = true;
}
else
errorProvider1.SetError(txtSalary, "");
}
Is there any way by which i can do something generic? Rather than declaratively defining the "Validating" event for each control(Form Design View -in controls properties) could i associate the event with the controls in a generic way through code?