2012-02-17 39 views
2

我有問題,爲什麼在單獨的中繼器中的2個控件如果它們位於更新面板中不能具有相同的ID,但它們可以共享如果它們不在更新面板中,則使用相同的ID。看到這個代碼...在中繼器的更新面板中匹配ID - 「已包含...的定義」

<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' 

但是,如果你不使用更新面板,像這樣它工作正常。

<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

這是否不適用於更新面板呢? 我可以使用相同的ID使上面的代碼工作嗎? - 請忽略這兩個中繼器應該是一箇中繼器的事實! :)

謝謝,查爾斯。

回答

2

這似乎是一個已知的bug,微軟已經決定不修復:

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.

+0

謝謝,我沒有穿過,在我的前谷歌搜索的問題來:) - 至少我知道我沒有做錯什麼! – 2012-02-17 15:31:03

+0

不客氣。我也沒有意識到這個問題,所以在這裏問這個問題很好:) – 2012-02-17 15:39:37

相關問題