Perform secondary validation on a form
Im using asp.net webforms. c#
I want to validate a form. In the codebehind im just doing a if(Page.isValid).
Once the form fields are valid i want to perform one more validati开发者_如何转开发on. The reason I want this separate is because it actually costs money to perform this validation, so I only want to perform it once the other fields are all valid.
Can I programatically add a validation error to a Validation summary? after checking Page.isValid?
Not sure how to tackle this.
Any suggestions welcome.
You could place a CustomValidator
with no ControlToValidate
attribute onto the page and set its IsValid
property by hand after all the other validation is done. This should make it show up in the summary.
If you are interested in a little more control over validation, you should look at FluentValidation. It is a very powerful and intuitive alternative to the standard webforms validation and you are able to keep your DTO classes clean of attributes. It also works very nicely in tandem with JQuery validation.
精彩评论