Microsoft KB Archive/834608

= FIX: You receive a &quot;Multiple controls with the same ID&quot; error message when you dynamically add cached user controls to Webforms =

Article ID: 834608

Article Last Modified on 4/7/2006

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft ASP.NET 1.1

-





SYMPTOMS
When you dynamically add cached user controls to an Webform, you receive an error message that is similar to the following when you browse to the Web page:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Multiple controls with the same ID '_909b6e15b33' were found. FindControl requires that controls have unique IDs.

Note The word &quot;web&quot; is capitalized incorrectly in this error message.

Note For more information about output caching and user controls, see the &quot;References&quot; section of this article.



CAUSE
This problem occurs because a unique name is passed to the LoadCachedControl function when dynamic controls are created from the cache. This unique name is intended to be the unique ID that is given to this instance of the dynamically loaded user control. However, a generated ID is used and the generated ID is not unique across the dynamically loaded user controls. This behavior causes the problem that is mentioned in the &quot;Symptoms&quot; section of this article.

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

837000 The PartialCachingControl.CachedControl property always returns a null reference



RESOLUTION
ImportantThis hotfix contains two types of packages: a Microsoft Windows Installer package, and an Optional Component Manager package (OCM). If you use Windows Server 2003, you must specify that you require the Windows Server 2003 (OCM) update, because Windows Server 2003 File Protection monitors the .NET Framework 1.1 files. If you use an operating system that is different from Windows Server 2003, you must continue to use the Windows Installer package.

Software update information
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft .NET Framework 1.1 Service Pack 1 that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Restart requirement
You may have to restart your computer if any services or applications are running that use files that are listed in the &quot;File information&quot; section of this article.

File information
The English version of this software update has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.   Date         Time   Version            Size    File name --  04-Feb-2004  04:14  1.1.4322.996      258,048  Aspnet_isapi.dll 04-Feb-2004 04:14  1.1.4322.996       20,480  Aspnet_regiis.exe 04-Feb-2004 04:14  1.1.4322.996       32,768  Aspnet_state.exe 04-Feb-2004 04:14  1.1.4322.996       32,768  Aspnet_wp.exe 16-May-2003 00:49                     33,522  Installpersistsqlstate.sql 16-May-2003 00:49                     34,150  Installsqlstate.sql 04-Feb-2004 04:05  1.1.4322.996       94,208  Perfcounter.dll 04-Feb-2004 04:10                      8,571  Smartnav.js   05-Feb-2004  05:11  1.1.4322.996    1,220,608  System.dll 05-Feb-2004 05:11  1.1.4322.996      241,664  System.messaging.dll 05-Feb-2004 05:11  1.1.4322.996      323,584  System.runtime.remoting.dll 05-Feb-2004 05:11  1.1.4322.996      131,072  System.runtime.serialization.formatters.soap.dll 05-Feb-2004 05:11  1.1.4322.996    1,257,472  System.web.dll 05-Feb-2004 05:11  1.1.4322.996      819,200  System.web.mobile.dll 05-Feb-2004 05:11  1.1.4322.996      569,344  System.web.services.dll 05-Feb-2004 05:11  1.1.4322.996    1,339,392  System.xml.dll 04-Feb-2004 04:10                     14,482  Webuivalidation.js



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section of this article.



Steps to reproduce the problem
 Create the Web folder, for example, create the \inetpub\wwwrooot\PageCaching folder.  Use the following code to create a user control that is named Test1.ascx, and then save it to the Web folder that was created in step 1: <%@ OutputCache Duration=&quot;60&quot; VaryByParam=&quot;none&quot; %> <%@ Control Language=&quot;c#&quot; &quot;%> Test 1 Control Dynamic   Use the following code to create a user control that is named Test2.ascx, and then save it to the Web folder that was created in step 1: <%@ OutputCache Duration=&quot;60&quot; VaryByParam=&quot;none&quot; %> <%@ Control Language=&quot;c#&quot; &quot;%> <asp:Label id=&quot;lblTest1&quot; runat=&quot;server&quot;>Test 2 Control</asp:Label> <asp:Label id=&quot;lblDynamic&quot; runat=&quot;server&quot;>Dynamic</asp:Label> </li>  Use the following code to create a Web form that is named PageCaching.aspx, and then save it to the Web folder that was created in step 1: void Page_Init(Object sender, EventArgs ev) {           Control Pane = Page.FindControl(&quot;uc1&quot;); Control Item = (Control) LoadCachedControl(&quot;test1.ascx&quot;, &quot;Dynamic1a&quot;); Pane.Controls.Add(Item);

Pane = Page.FindControl(&quot;uc2&quot;); Item = (Control) LoadCachedControl(&quot;test2.ascx&quot;, &quot;Dynamic2a&quot;); Pane.Controls.Add(Item);

Pane = Page.FindControl(&quot;uc3&quot;); }

public PartialCachingControl LoadCachedControl(string r_ControlName, string r_ControlID) {           PartialCachingControl Control = (PartialCachingControl) Page.LoadControl(r_ControlName); Control.ID = r_ControlID; return Control; }

<%@ Page language=&quot;c#&quot; %> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; > <HTML> <HEAD> WebForm1 <meta name=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio .NET 7.1&quot;> <meta name=&quot;CODE_LANGUAGE&quot; Content=&quot;C#&quot;> <meta name=&quot;vs_defaultClientScript&quot; content=&quot;JavaScript&quot;> <meta name=&quot;vs_targetSchema&quot; content=&quot;http://schemas.microsoft.com/intellisense/ie5&quot;> </HEAD> <form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;> </HTML> </li> Browse to http://localhost/PageCaching/PageCaching.aspx. You receive the error message that is described in the &quot;Symptoms&quot; section of this article.</li></ol>

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates

Using the PartialCachingControl class
The PartialCachingControl class has a CacheControl property. The CacheControl property can be used to determine if a user control has already been cached. The CacheControl property returns the user control only when the output of the user control output is not cached. If the user control output exists in the output cache, the CacheControl property returns a null reference because the control is never instantiated (in Microsoft Visual Basic, the CacheControl property returns Nothing). However, the CacheControl property always returns FALSE if the PartialCachingControl class is not in the control tree.

<div class="references_section">