Re: Multiple controls with the same ID '_ctl11'

From: S. Reddi (sreddi_at_razorhost.com)
Date: 03/18/04


Date: 18 Mar 2004 06:57:53 -0800

Alessandro, thanks for replying.

If you look at the client side HTMl that is generated you don't see a
duplicate ID (or name attribute which is what the form post uses)
which, is why this issue is hard to debug. Further, the same code
that renders this page will execute successfully on prior posts.

So, here is the client side HTML that generates the exception on
postback:

<html><head><title></title><link rel='style***' href='css/brand.css'
type='text/css'><script language='javascript1.2'
src='script/utility.js'></script></head><div id='maindiv'
style='z-index:500'><body onload='' id='' leftmargin='0'
topmargin='0' rightmargin='0'><form name="_ctl5" method="post"
action="WebForm1.aspx" id="_ctl5">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTA2NjU0MDExNzs7Pm9cl/yR2wqdiUfAXAr/MGVu81OV" />
<div>

</div><table valign='top' cellspacing='0' cellpadding='0' border='0'
align='left'><tr valign='top' align='left'><td colspan='20'>
<p><font style="FONT-SIZE: 20pt; FONT-FAMILY: 'Arial
Black'">id="Device2"
                runat="server" Target="Header" - THIS IS A HEADER</font></p>
<P>
        <input type="submit" name="_ctl8:Button1" value="Button"
id="_ctl8_Button1" /></P>
</td></tr><tr valign='top'><td><!--MENU-->
<p>id="DeviceMenu" runat="Server" Target="Menu"</p>

</td><td valign='top' align='left'><!--BODY-->
<p>id="DeviceOne" runat="server" Target="Body"</p>
<P><span id="_ctl12_Label1">Name:</span><input name="_ctl12:TextBox1"
type="text" id="_ctl12_TextBox1" /></P>
<P></P>
<P><input type="submit" name="_ctl12:cmdProcess" value="Enter"
id="_ctl12_cmdProcess" /></P>
</td><td valign='top'><!--AD-->
<p>id="DevAdvertise" runat="server" Target="Ad"</p>
</td></tr></table></form></body></div></html>

Controls are preloaded like this after a recursive function searches
all sub-dirs for ASCX files:

tmpArrayList.Add((UserControl)this.Page.LoadControl(strFile));
                                
UserControls are added like this (only controls that contain an
instance of ABaseDevice and match the load list will be added ):

bodyplaceholder.Controls.Add(uc);
menuplaceholder.Controls.Add(uc);
etc..

Also, I am looking for someone with experience with this particular
problem as I am sure that any developer that has preloaded ASCX files
using LoadControl into an array and then adds them as needed to a
placeholder or panel will have encountered this problem. This problem
will not occurr if you use multiple ASPX files and call LoadControl
each time to load the ASCX.

Thanks.

"Alessandro Zifiglio" <alessandrozifiglio@No-Spam--hotmail.com> wrote in message news:<O4gIONMDEHA.4080@TK2MSFTNGP09.phx.gbl>...
> hi Reddi, I'm not clear with your problem. Even though you have tried to
> elaborate on what is going on, the info you have provided is very scarce and
> makes it very difficult to provide you with any help. I can only tell you
> that the error is thrown because as the error states you have more than one
> control on your page, that has the same ID on it. To verify this, go in the
> "view source" of your page as it renders in IE and check the ID attributes,
> you will notice this. The reason why this error is throw only after postback
> is because asp.net tries to reference you control as it postsback but
> because of the multiple ID issue, is having problems. Recheck your code,
> execute it in debug mode, run it line by line, see what happens, check to
> see where you are supplying the same ID --or how you are supplying the ID
> for your dynamic controls.
>
> Thats about all the help I can give you right now ;P


Loading