Attaching a validator to a composite control

P

Peter Young

I would like to have my control provide a Required property, and if this
property is true, attach a RequiredFieldValidator.

This approach works fine for a 'simple' control, but it fails for a
composite control, where the control is implementing INamingContainer.

It appears that the problem is inside of the system base validator - it is
looking for the ControlToValidate like so:
this.NamingContainer.FindControl(name)

In this case, the naming container is the control it's trying to find, so it
can't find it. It needs to search the parent naming container.

Has anyone else run into this and found a simple workaround?

Thanks for any help,
Pete
 
P

Peter Young

Hi Peter,

Thanks for the info. It backs up what I believed to be true. I ended up
creating a required field validator which replicates the system's as well as
a base validator which derives from the system's. This lets me override the
necessary methods to correct the naming container issue. A bit of a PITA,
but now I have a clean solution for all the controls in my assembly that
need it.

-Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top