SelfValidation does not fire when used with Validation.Integration.Winforms

Topics: General discussion, Validation Application Block
Dec 18, 2008 at 5:49 PM
Most likely is me missing the obvious.

I have a form i have successfully managed to validate all the textBoxes.Using Config File approach and the Validation.Integration.Winforms.

However when input a creditcard number i would like to use selfValidation to validate a method to perform a check.

What I did is as follows
Using the same class I  added the attribute "HasSelfValidation and then added a method "ValidateCard" with SelfValidation On it.

In my dummy  form there is no code at all.I was expecting the the selfValidation to kick in at some point by some form of magic.

Does SelfValidation work only if you validate programmatically and cannot use ValidationProvider for it?

Thanks a lot for any suggestions.
Dec 19, 2008 at 2:19 AM
Methods with SelfValidation attribute fires if you validate a class which contains  that method. 

public class Foo
    public void Check(ValidationResults results)
            //code here

    Foo foo = new Foo();
    //This will trigger the Check method
    ValidationResults results = Validation.Validate<Foo>(foo);

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Dec 19, 2008 at 8:17 AM
Thanks a lot for your reply.
That works.
Is it correct to say that then I would be validating twice ,
1)because most of the textboxes uses the ValidationProvider approach with config approach ,so as soon as i try to move out of focus it will validate
2)and the second time by manually triggering a class validation everything will be validated again.

I am inclined to remove the winform integration and trigger the validation programmatically,however i would have write code to set and clear the error provider for each textbox.

thanks again

Dec 19, 2008 at 9:03 AM
Sorry, I"m not sure what ValidationProvider you are referring to.  Could you clarify this?

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Dec 19, 2008 at 2:03 PM
I mean the Integration.WinForm control that  you drop on the form and then you map it to an Error provider.

Thanks again
Dec 20, 2008 at 1:17 AM
Oh, I see. Yes, validation would happen twice if you do that.  If you can't avoid using SelfValidation, you can't avoid trigerring the validation programmatically.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Dec 20, 2008 at 5:33 AM
thanks for your time and help