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
 
Ad

Advertisements

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
 
Ad

Advertisements

K

Keith Patrick

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

Advertisements


Top