c# - validation using error provider and stop further execution -


i want validate winform using error provider. when user click on button multiple validated methods executed txtfieldone_validated(this, e); txtfieldtwo_validated(this, e); , need solution stop execution further if of validators fails , display error using error provider.

i thought use private variable bool _formvalid

private btnvalidatefields_click(object sender, eventargs e) {    txtfieldone_validated(this, e);     txtfieldtwo_validated(this, e);      if(_formvalid)    {continue...} }  private void txtfieldone_validated(object sender, eventargs e) {     if(....)         errorprovider1.seterror(txtfieldone, "some error message")        _formvalid = true;     else(....)        errorprovider1.seterror(txtfieldone, "")        formvalid = false; } 

but using approach if last checked field true populated _formvalid remains true , form pass.

i not clear trying do. per comments, suggest this.there no need call different validation method different controls. controls should validated in same method.

void isformvalid(this, e) {     bool result = validateallcontrols();      if(!result)         return;      // rest of execution }  bool validateallcontrols() {     if(!control1.isvalid)         return false;     if(!control2.isvalid)         return false;     if(!control3.isvalid)         return false;      return true; } 

let me know if misunderstood something.

hope helps.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -