12

I am trying to upgrade an ASP.NET application to .NET 4, but one page on my site contains an exception:

Argument Exception: an entry with the same key already exists".

What is different about ASP.NET 4 that might cause this problem?

enter image description here

One Solution

Not sure why but setting clientIDMode="Predictable" rather than Static seems to have avoided this exception message.

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Tom
  • 12,776
  • 48
  • 145
  • 240

3 Answers3

7

I had the same issue and fixed it.

I went through my entire ASPX page and found ASP.NET control that had the same ID as another.

I also tested this fix, and found that any control that conflicts with another control on the page will cause this error.

<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />

<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />

It happens when you Copy/Paste elements on the same page.

Ravi Ram
  • 24,078
  • 21
  • 82
  • 113
  • 1
    how is this possible! unless visual studio does not let it to compile and point to duplicates id. this error is freaking me out – Iman Jul 26 '13 at 13:08
  • @imanabidi when you copy/paste in VS sometimes it changes the ID, other times, it does not. You need to check to make sure each element on the page has a unique ID. – Ravi Ram Jul 26 '13 at 17:40
  • but in VS 2012 it just does not let me to do that even with copy/paste.however my problem was setting multiple Items'Selected property equal to true in DropDownList items Collection – Iman Jul 30 '13 at 06:00
  • :thank you very much. I mean I solved my problem with resetting all previously selected items with setting selectedIndex=-1 . – Iman Jul 30 '13 at 14:17
0

This in your web.config may also cause the error by allowing duplicate IDs

<pages clientIDMode="Static">
SkyReel
  • 160
  • 10
0

I have this error too and not resolve with this

<pages clientIDMode="Static">

my datagrid work fine this :

I have gridview :

 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" CancelText="لغو" DeleteText="حذف" EditText="ويرايش" UpdateText="بروزرساني">
                            <ControlStyle CssClass="btn btn-xs btn-default" />
                            <ItemStyle Width="143px" />
                        </asp:CommandField>



                        <asp:BoundField DataField="ID" HeaderText="#" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
                        <asp:BoundField DataField="Title" HeaderText="عنوان" SortExpression="Title" />
                        <asp:BoundField DataField="ParentID" HeaderText="پدر" SortExpression="ParentID" />
                        <asp:BoundField DataField="Url" HeaderText="آدرس" SortExpression="Url">
                            <ItemStyle CssClass="ltr"></ItemStyle>
                        </asp:BoundField>

                        <asp:BoundField DataField="Icon" HeaderText="آيکون" SortExpression="Icon" />

                        <asp:BoundField DataField="Order" HeaderText="اولويت" SortExpression="Order" />

                    </Columns>
                </asp:GridView>

but after add image field i see this error

      <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" CancelText="لغو" DeleteText="حذف" EditText="ويرايش" UpdateText="بروزرساني">
                            <ControlStyle CssClass="btn btn-xs btn-default" />
                            <ItemStyle Width="143px" />
                        </asp:CommandField>


                        <asp:ImageField  ReadOnly="true"  SortExpression="Icon" DataImageUrlField="icon">
                        </asp:ImageField>

                        <asp:BoundField DataField="ID" HeaderText="#" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
                        <asp:BoundField DataField="Title" HeaderText="عنوان" SortExpression="Title" />
                        <asp:BoundField DataField="ParentID" HeaderText="پدر" SortExpression="ParentID" />
                        <asp:BoundField DataField="Url" HeaderText="آدرس" SortExpression="Url">
                            <ItemStyle CssClass="ltr"></ItemStyle>
                        </asp:BoundField>

                        <asp:BoundField DataField="Icon" HeaderText="آيکون" SortExpression="Icon" />

                        <asp:BoundField DataField="Order" HeaderText="اولويت" SortExpression="Order" />

                    </Columns>
                </asp:GridView>
Ajay2707
  • 5,690
  • 6
  • 40
  • 58
Tarrah Arshad
  • 74
  • 2
  • 9