SelfValidation and ASP.NET Integration

Topics: Validation Application Block
Jun 14, 2007 at 7:39 PM
Is there a way to have SelfValidation kick when ASP.NET initiates the validation? I'm assuming not, as I have a breakpoint in my SelfValidation method and it never gets hit. Anyone know if this is possible?
Jun 14, 2007 at 10:29 PM
Hi,

No, it's not possible to use SelfValidation with ASP.NET. Self validation relies on a message executed on an instance of the type where the validation is defined, and the integration with ASP.NET applies the validation logic to the values of the controls and does not create an instance of the target type.

If you rely on self validation you can use a custom ASP.NET validator and write code in the validator handler to create an instance of the validated type and invoke validation through the validation facade.

HTH,
Fernando
Jun 14, 2007 at 10:47 PM
Great suggestion! I didn't realize that an instance of the type was not being created. That makes sense.
Aug 24, 2007 at 9:23 AM
Hi,

Does the same thing apply for WCF integration?

Sincerely
Herbjörn
Aug 24, 2007 at 4:07 PM
Hi,


herbjorn wrote:
Does the same thing apply for WCF integration?


Yes and no, depending on what you mean. Yes, you can use custom validators with WCF integration, but no, the use of self validations is not precluded (assuming self validation is implemented by a method in your data contracts, which may not be appropriate).

Regards,
Fernando

Aug 24, 2007 at 5:04 PM
Hi,

If it's not precluded then it is possible, but I do not know how to specify this in configuration. Any tip?

Sincerely
Herbörn
Aug 27, 2007 at 4:01 PM
Hi,

You cannot configure as self validation method through configuration; only attributes can be used for this. However, you should be able to configure the method using the attribute with a specific ruleset name, and then specify through config an ObjectValidation for that ruleset.

Regards,
Fernando