Home All Groups Group Topic Archive Search About

Error: Multiple controls with the same ID '1' were found.

Author
20 Jan 2006 9:19 PM
vibs
I am getting the following error when dynamically adding
RequiredFieldvalidator control to a Table.
Multiple controls with the same ID '1' were found. FindControl requires that
controls have unique IDs

I get this error only on validator control and not on labels or textbox, so
if I was to replace the same control with a label or textbox, it works fine.
Here is the code,

   case "RequiredFieldValidator":
                RequiredFieldValidator cReq = (RequiredFieldValidator)ctrl;
                cReq.ID = System.Guid.NewGuid().ToString();
                mcell.Controls.Add(cReq);
                break;

Thanks for your help!
Vibs

Author
20 Jan 2006 9:28 PM
Phillip Williams
It is for this kind of situation that control designers would implement the
INamingContainer http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiinamingcontainerclasstopic.asp

"Any control that implements this interface creates a new namespace in which
all child control ID attributes are guaranteed to be unique within an entire
application. "

Show quoteHide quote
"vibs" wrote:

> I am getting the following error when dynamically adding
> RequiredFieldvalidator control to a Table.
> Multiple controls with the same ID '1' were found. FindControl requires that
> controls have unique IDs
>
> I get this error only on validator control and not on labels or textbox, so
> if I was to replace the same control with a label or textbox, it works fine.
> Here is the code,
>
>    case "RequiredFieldValidator":
>                 RequiredFieldValidator cReq = (RequiredFieldValidator)ctrl;
>                 cReq.ID = System.Guid.NewGuid().ToString();
>                 mcell.Controls.Add(cReq);
>                 break;
>
> Thanks for your help!
> Vibs
Author
20 Jan 2006 9:55 PM
vibs
Phillip,

I am not creating a new control. I am just using an existing
RequiredValidator Control.

Thanks

Show quoteHide quote
"Phillip Williams" wrote:

> It is for this kind of situation that control designers would implement the
> INamingContainer
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiinamingcontainerclasstopic.asp
>
> "Any control that implements this interface creates a new namespace in which
> all child control ID attributes are guaranteed to be unique within an entire
> application. "
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "vibs" wrote:
>
> > I am getting the following error when dynamically adding
> > RequiredFieldvalidator control to a Table.
> > Multiple controls with the same ID '1' were found. FindControl requires that
> > controls have unique IDs
> >
> > I get this error only on validator control and not on labels or textbox, so
> > if I was to replace the same control with a label or textbox, it works fine.
> > Here is the code,
> >
> >    case "RequiredFieldValidator":
> >                 RequiredFieldValidator cReq = (RequiredFieldValidator)ctrl;
> >                 cReq.ID = System.Guid.NewGuid().ToString();
> >                 mcell.Controls.Add(cReq);
> >                 break;
> >
> > Thanks for your help!
> > Vibs
Author
20 Jan 2006 9:29 PM
Keith Patrick
try:
mcell.Parent = this;


ASP renders the ID as ClientID (or UniqueID, I can never remember), which
qualifies them via the IDs of the parental hierarchy.  However, the parent
must be non-null, so I am guessing that mcell has no parent at this point?
Author
20 Jan 2006 10:02 PM
vibs
Keith,
mcell.parent is a readonly property. I am adding the control to a cell in a
table. I so see the mcell.parent has a uniqueid on each iteration. And again
this is happening only for validator controls so something else is going on
here....

Thanks
Vibs

Show quoteHide quote
"Keith Patrick" wrote:

> try:
>  mcell.Parent = this;
>
>
> ASP renders the ID as ClientID (or UniqueID, I can never remember), which
> qualifies them via the IDs of the parental hierarchy.  However, the parent
> must be non-null, so I am guessing that mcell has no parent at this point?
>
>
>
Author
21 Jan 2006 1:05 AM
Keith Patrick
Sorry about that...forgot that it gets set during Controls.Add (I didn't
compile it to check)