IValidator and Validation Groups

IValidator and Validation Groups

Post by brantma » Wed, 02 Aug 2006 04:48:33

Here is a question that needs to be revisited. I noticed that there are
more that a few posts about this in this group and in custom controls.
Here is the problem:
When inheriting from a webcontrol, say textbox for example, and
implementing the IValidator interface to make the control
self-validating, the control fails to participate in validation groups.
Using reflector, it is easy to see why; the page.validator casts all
the controls in the collection to BaseValidator, thus a control derived
from a TextBox implementing IValidator gets cast to Nothing (Null).
However all the correct attributes and abilities are there. So the
question that still remains unanswered by all the .NET gurus in this
group is-- How can a control created as aformentioned be forced to
participate in the validation groups of ASP.Net 2.0?

Some thoughts of mine are: Cast the control myself using a custom type
caster?? Is this possible?
Perhaps I could create a basevalidator object in my control and using
delegates have it still fire my Validate() function of my control and
modify the isValid property and display the message i have set up.
This seems very complicated and riddled with opportunities for even
greater obsticals that the one I am trying to overcome.
Use a composit control that includes a custom validator derived from
BaseValidator. This is the most strait foward for the validation
groups, but complicates the rest of the control.
To see the code used for my Textbox self validating control, look at my
forums http://www.yqcomputer.com/

1. IValidator - multiple error messages

2. Validationgroups and IValidator problem (ASP.NET 2.0)

Hi all,

I have a serious problem with asp.net validation: I developed a custom
validation summary control, which will lookup error messages from an external
source based on the BaseValidator.ErrorMessage property. This validation
summary control has a custom method which will add a dummy validator (which
will always evaluate to false) to the Page.Validators collection. The dummy
validator implements the IValidator interface, and this structure worked fine
on ASP.NET 1.1.

However, ASP.NET 2.0 supports validation groups, so I decided to add a
custom 'ValidationGroup' property to the dummy validator class, because I
want my custom validation summary control to support this much-welcomed
feature. The problem is that the Page.GetValidators(string validationGroup)
will loop through the page's Validators collection and cast each validator to
a BaseValidator! This way, my custom validator is casted to a null value and
won't be added to the collection of validators returned by the
Page.GetValidators method.

Does anybody have any suggestions how to resolve this?


Arnold Jan van der Burg

3. implement Ivalidator interface on an ASP.NET page.

4. IValidator and ValidationGroup

5. TextBox:IValidator and a star (*)

6. Nesting ,Ands

7. Multiple Nested IFs, ORs, Ands

8. Omnipage 14 ands its PDFs

9. Multiple ANDs

10. Concatenating date field into text ands using in a formula

11. Conditional Statement with ANDs

12. multiple ifs & ands indirect/offset...need help desperately pl

13. Sumproduct assistance - need multiple ANDs and ORs

14. IFs ANDs and ORs

15. WMP11 BUG: Advanced Search doesn't work with ANDs