Change public void to public boolean, after the error is detected return false, if it goes all the way through return true.
Save depending on your validation result.
If (ValidateFields) {
// save to database
}
New version for validate function only IF ALL NEED TO VALIDATED:
public void ValidateFields()
{
var controls = new[] { txt_PartyName, txt_ContactPerson, txt_mobile1, txt_add, txt_city, txt_state, txt_PinCode };
boolean isValid = true;
foreach (var control in controls.Where(e => String.IsNullOrWhiteSpace(e.Text)))
{
errorProvider1.SetError(control, "Please fill the required field");
isValid = false;
}
return isValid;
}
If this helps, please take time to accept the solution so others may find it. Thank you.