System.ArgumentException: An entry with the same key already exists

萝らか妹 提交于 2019-12-06 03:38:10

You are a lucky to have an error cause in very first rows of your code. Because I'm just horrified by it. Change your validator's ClientIDMode to Predictable.

after 2 hours I found a solution for the following exception .

[ArgumentException: An entry with the same key already exists.]
   System.Collections.Specialized.ListDictionary.Add(Object key, Object value) +6888908
   System.Web.UI.ClientScriptManager.RegisterExpandoAttribute(String controlId, String attributeName, String attributeValue, Boolean encode) +340
   System.Web.UI.ScriptRegistrationManager.RegisterExpandoAttribute(Control control, String controlId, String attributeName, String attributeValue, Boolean encode) +113

in my case it was because selected was true for more than one item in DropDownList Items dictionary

 if (DropDown.Items.FindByText(value) != null) {
      //important note:  
      //below line will reset selected true if previously this field is set and  caused the exception and must be removed
      //DropDown.SelectedIndex = -1;
      DropDown.Items.FindByText(value).Selected = true;
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!