cbp
cbp

Reputation: 25638

Debug this error: Multiple controls with same ID 'ctl00$ctl00$ctl34' were found

For literally years, my website has very intermittently thrown the following exception:

Multiple controls with the same ID 'ctl00$ctl00$ctl34' were found. Trace requires that controls have unique IDs.

at System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize, Int32 controlStateSize)

at System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState)

.... etc (entire stack trace is within System.Web namespace)

at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Sometimes a user will go to a page and this exception will be thrown - it happens on different pages and different control ids show up. Often, reloading the page will work. Other times, the exception will persist for a few refreshes before fixing itself.

Now I know that this error usually occurs when you are adding dynamic controls to a page and you accidently use the same ID within the one naming container, so I understand the meaning of the error.

But on my site, I am not adding dynamic controls. At least not that I know of.

I am running third-party components like Umbraco, Telerik and Peter Blum, and they are almost certainly adding control dynamically to the control tree at times, but, like I said, this error has been around for years, across major versions of all of these modules.

The intermittent nature of the exception suggests some sort of multi-threaded timing issue or use of a random number somewhere. Who knows... I can't find the cause of it in my code.

So my question is - how could I go about debugging this issue, given that the entire stack trace is within the .NET framework?

Upvotes: 3

Views: 2258

Answers (3)

user764200
user764200

Reputation: 51

If you are dynamically creating data-bound controls then make certain they are added to the page, or control on the page, before calling the DataBind() method.

Upvotes: 0

p.campbell
p.campbell

Reputation: 100607

It sounds like you're asking for troubleshooting steps or ideas.

Perhaps one of these might help:

  • catalog all the page names or URLs where this exception has occurred. Is it the same page? Is it a group of pages that have one of the 3rd party controls on it? Do those pages have a mixture of many 3rd party controls (i.e. Telerik AND Blum)?

  • are there any hints in Event Viewer as to which might be the culprit?

  • do any of those 3rd party controls have any APIs for logging?

  • do the APIs for those 3rd party controls allow for any 'help', or seed, or convention in naming?

  • consider ASP.NET 4's New ClientIDMode Property as a possible potential solution. I guess it'd be up to the vendor to have implemented. Perhaps convert your app to .NET 4 in a Test environment, and see if that can be reproduced? I suspect since it's random in nature, you might not be able to predictably repro this problem.

Upvotes: 0

Aristos
Aristos

Reputation: 66641

From my experience this happens when you update pages (files) on your server with out first open the app_offline.htm , and at the same time some user try to open your site.

Especial if you update the files from ftp (thats take some time) or when you upload only the aspx or only the code behind file.

So while you uploading the files, the asp.net trigger the compilation because he finds some different on file, but because the files are not fully updated, there is a mess up with the compiled dlls.

  • I suggest to first open the asp_offline.htm file.
  • I also suggest if you try to update only one or two files, then update them both aspx and code behind file.
  • If you see this problem a quick solve is to open the asp_offline.htm file, just open web.config, make a line and saved it, and remove asp_offline.html. That way you give a signal to update again the site and find all the changes.

Other possible way is to disable the optimize on compile and force him to compile most of the files, even tho I think that this trick not work on me.

<compilation optimizeCompilations="false">

Hope this help.

Upvotes: 2

Related Questions