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

V

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
 
K

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?
 
V

vibs

Phillip,

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

Thanks
 
V

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
 
K

Keith Patrick

Sorry about that...forgot that it gets set during Controls.Add (I didn't
compile it to check)
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top