1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Preventing duplicate Control IDs

Preventing duplicate Control IDs

4 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    03 May 2010
    Link to this post
    Ive got a control that posts back to download a file, but if I have multiple verisons of this control I get this error

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

    I can change the IDs in the admin area myself to fix it, but my admins will have no idea what's going on

    Is there a way to handle this?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 May 2010
    Link to this post
    Hello Steve,

    The error could appear if something was added to the page before it was supposed to.
    Usually this is caused by calling DataBind too soon or .ClientID. This could happen if you are calling something that is not part of the  page controls hierarchy yet - for instance calling.ClientID before OnPreRender. You can try to narrow down the issue using a clean page that does not uses and js, css and other controls and drag/drop controls one by one. You could also try using a "clean" control - just one Literal or Label declaratively added to the template of the control and noting in the code behind.
    You could share with us steps you follow, so we could try to reproduce the problem locally and figure out what the problem is.

    The quick fix to this issue would be setting the control ID from the code behind to a random value. You could use Random Class to generate random number  and assign it to the ID of the control. This will ensure that each control has unique ID.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    03 May 2010
    Link to this post
    Yeah that's pretty much what I've been doing, assigning a Guid to the value needing a ClientID

    But in the advanced tab, the ID column at the top...that's never unique by default each time a new version of a control gets dropped onto the page?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 May 2010
    Link to this post
    Hello Steve,

    Setting the ID on Page_Load should work. If the problem persists, please send a sample that we could use to reproduce the problem.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
4 posts, 0 answered