I'm writing an ASP.NET page and trying to get validation working. My problem is that I've got a repeater that contains several custom grid controls, each of which has validators and a validation summary.
At first, I didn't assign any validation groups, but this ended up making validation summaries appear for every grid whenever there was an error in one (because the validation summary's validation group was not set, I suppose, which meant it captured all validation errors).
So I assigned a separate validation group for each grid, unique with respect to a certain property on the control. But I have a button at the bottom of the page (with no validation group) that needs to validate the input. Not having a validation group, it won't automatically validate the grids' validators, so I added a click handler that calls Page_ClientValidate()
. No dice--validation appears everywhere.
Okay, so I iterate through the validation groups and call Page_ClientValidate(validationGroup)
on each if it has any validators. Works fine when only one grid has validators, but when two or more do, it automatically hides all validation summaries but the last one checked. Is there any way to disable this behavior, or a better way to do this entirely?
If I need to, I guess I can go through and unhide the other validation summaries once I've finished iteratively validating (although that might possibly have other implications), but I'd also need to unhide the validator displays (I'm using an image to denote invalid fields). It seems like such an annoying and possibly fragile solution.
EDIT: Oh, a twist. I tried doing the approach I mentioned at the end--re-showing the hidden validators/validation summaries that are invalid--but the Microsoft code prevents that, too; in the first line of the ValidatorValidate(validator, validationGroup, event)
method (called by Page_ClientValidate(validationGroup)
on each validator in the page), validator.isvalid
is set to true
, and is only set to the return value of the validation function within a conditional that only runs if the validationGroup
parameter matches the validator's. The upshot being, the hidden validators all are marked as valid, making it tough to determine after the fact whether a validator is valid because it's actually valid or because Microsoft was stupid in designing the client-side validation code.