Repeater中匹配更新面板中的ID - "已经包含了定义..." [英] Matching IDs in Update Panel within a Repeater - "already contains a definition for..."

查看:140
本文介绍了Repeater中匹配更新面板中的ID - "已经包含了定义..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为什么在不同的中继器2控件不能有相同的ID,如果他们是一个更新面板内的问题,但如果他们不是在一个更新面板,他们可以共享相同的ID。看到这个code ...

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>

生成此错误:

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>

据我了解,中继器中的所有控件都给出艾克新的IDS的东西...
ctl00_cttBody_ucTestControl_rptFirstRepeater_ctl00_imgThisWorks

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

这是否不适用于更新面板呢?
我将能够使用相同的ID在code以上的工作? - 请忽略的事实是,这些2个中继器确实应该一个中继! :)

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! :)

谢谢,查尔斯。

推荐答案

这似乎是一个已知的bug微软已决定不修复:

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

<一个href=\"http://connect.microsoft.com/VisualStudio/feedback/details/417230/updatepanel-breaks-naming-containers-compile-time-bug\" rel=\"nofollow\">http://connect.microsoft.com/VisualStudio/feedback/details/417230/updatepanel-breaks-naming-containers-compile-time-bug

在这个时间点上,我们已经决定不修复这个具体问题。
  幸运的是,有一个非常简单的解决方法 - 避免使用相同
  内,外的UpdatePanel控件的ID。

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.

这篇关于Repeater中匹配更新面板中的ID - &QUOT;已经包含了定义...&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆