Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Attaching a validator to a composite control

Reply
Thread Tools

Attaching a validator to a composite control

 
 
Peter Young
Guest
Posts: n/a
 
      01-29-2005
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


 
Reply With Quote
 
 
 
 
Peter Young
Guest
Posts: n/a
 
      02-02-2005
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

"Peter Blum" <> wrote in message
news:#...
> Hi Pete,
>
> By design, the ControlToValidate property is limited to the current naming
> container (which you've proven.)
>
> The typical answer is to the confirm that all controls are in the same
> naming container. One way you might do this is by adding the
> RequiredFieldValidator inside your customcontrol when the Required

property
> is true. They will both be in the same naming container.
> Another is to determine if your control truly needs an INamingContainer.
> Often when a composite control creates child controls, it assigns their

IDs
> based on its own ID in the CreateChildControls method. So long as the page
> developer assigns the ID property to the control before

CreateChildControls
> is called, everything has a unique ID and will work fine without
> INamingContainer.
>
> FYI: I built a replacement to Microsoft's validators (see my tagline). It
> overcomes numerous limitations in validation including the

INamingContainer
> one. On my validators, you can either assign the ID or a reference to the
> control. When you assign a reference to the control, it can be in any

naming
> container. When you assign an ID it can be in the same or any parent

naming
> container.
>
> --- Peter Blum
> www.PeterBlum.com
> Email:
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
>
> "Peter Young" <> wrote in message
> news:...
> >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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
custom validator and ControlToValidate in a composite control... Donal McWeeney ASP .Net Building Controls 1 09-29-2004 08:45 AM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
Help attaching validator controls to an undetermined number of contorls in a repeater Simon ASP .Net 1 05-17-2004 04:12 AM
Composite control with dynamic composite controls sleigh ASP .Net 1 02-12-2004 06:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57