Sunday, March 11, 2012

Error: "Multiple controls with the same ID _ClientState were found" when creating multiple

Hi PhxSportsGuy,

Would you please give us a simple repro which can reproduce your problem? So we can troubleshoot in your shoes. Thanks

Best regards,

Jonathan


Hi Jonathan,

I have found that the _ClientState hidden control is being created prior to me setting the ID field.

My code looks as follows:

Dim objCollapsiblePanelExtenderAsNew CollapsiblePanelExtender
objPlaceHolder.Controls.Add(objCollapsiblePanelExtender)

With objCollapsiblePanelExtender
.ID = strCollapsiblePanelExtenderID
(additional settings)
EndWith

Notice that I add the CollapsiblePanelExtender control to the Place Holder controls collection prior to setting the ID.

If I change the code to:

Dim objCollapsiblePanelExtenderAsNew CollapsiblePanelExtender

With objCollapsiblePanelExtender
.ID = strCollapsiblePanelExtenderID
(additional settings)
EndWith

objPlaceHolder.Controls.Add(objCollapsiblePanelExtender)

If I immediately set the ID before adding the CollapsiblePanelExtender to the PlaceHolder collection, then everything works correctly.

Thanks for your help,

Len


I am running into the same issue when I created two custom controls using MaskedEditExtender and placed both controls in the a page to test.

I created controls for phone number and Date by using MaskedExitExtender. I tested phone number control alone and that works fine.As soon as I add the Date custom control to the page I get this error message.

"Multiple controls with the same ID '_ClientState' were found. FindControl requires that controls have unique IDs."


From what I can tell, what matters most in this error is simply setting the ID property before adding the control to the page.

For instance:

CustomControl ccA =new CustomControl();panel.Controls.Add(ccA);ccA.ID ="ControlA";CustomControl ccB =new CustomControl();panel.Controls.Add(ccB);ccB.ID ="ControlB";// Error.// --OR--CustomControl ccA =new CustomControl();ccA.ID ="ControlA";panel.Controls.Add(ccA);CustomControl ccB =new CustomControl();ccB.ID ="ControlB";panel.Controls.Add(ccB);// No error.
Set the ID first, then add the control to the page. It doesn't matter if you set the ID one line above adding the control, or if you set it a thousand lines above in a separate file, just as long as it is set before adding it to the page.
 I hope this helps. :) 

No comments:

Post a Comment