Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching IDs in Update Panel within a Repeater - "already contains a definition for..."

I have question about why 2 controls in separate repeaters cannot have the same ID if they are within an update panel, but they can share the same ID if they are not in an update panel. See this code...

    <asp:Repeater ID="rptFirstRepeater" runat="server">
        <ItemTemplate>
            <asp:Image runat="server" ID="imgThisWorks" />
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <asp:Image runat="server" ID="imgThisDoesntWork" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </ItemTemplate>
    </asp:Repeater>

    <asp:Repeater ID="rptSecondRepeater" runat="server">
        <ItemTemplate>
            <asp:Image runat="server" ID="imgThisWorks" />
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <asp:Image runat="server" ID="imgThisDoesntWork" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </ItemTemplate>
    </asp:Repeater>

Generates this error:

CS0102: The type 'ASP._8_admin_testemail_aspx' already contains a definition for 'imgThisDoesntWork'

But it works fine if you don't use the update panel, like so.

    <asp:Repeater ID="rptFirstRepeater" runat="server">
        <ItemTemplate>
            <asp:Image runat="server" ID="imgThisWorks" />
        </ItemTemplate>
    </asp:Repeater>

    <asp:Repeater ID="rptSecondRepeater" runat="server">
        <ItemTemplate>
            <asp:Image runat="server" ID="imgThisWorks" />
        </ItemTemplate>
    </asp:Repeater>

I understand that all controls within repeaters are given new ids something lke... ctl00_cttBody_ucTestControl_rptFirstRepeater_ctl00_imgThisWorks

Does this not apply to the update panel as well? Would I be able to make the code above work using the same IDs? - please ignore the fact that these 2 repeaters should really be one repeater! :)

Thanks, charles.

like image 877
Charles Philip Avatar asked Dec 30 '25 11:12

Charles Philip


1 Answers

It seems to be a known bug which microsoft has decided not to fix:

http://connect.microsoft.com/VisualStudio/feedback/details/417230/updatepanel-breaks-naming-containers-compile-time-bug

At this point in time, we've decided not to fix this specific issue. Fortunately, there's a very simple workaround - avoid using the same control ID inside and outside the UpdatePanel.

like image 132
Tim Schmelter Avatar answered Jan 01 '26 02:01

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!