已存在具有相同密钥的条目。

问题描述:

运行应用程序时出现以下错误...



在此页面中,我将动态添加到表中的行和包含下拉列表的行,每个控件具有不同ID的文本框和必填字段验证器。



I am getting the below error while running the application ...

In this page I am adding rows dynamically to a table and the rows containing dropdown list,text boxes and required field validator with different ID for each control.

Server Error in '/' Application.
--------------------------------------------------------------------------------

An entry with the same key already exists. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

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

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


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

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +251
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
   System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) +2377
   System.Web.UI.WebControls.ValidatorCompatibilityHelper.RegisterExpandoAttribute(Control control, String controlId, String attributeName, String attributeValue, Boolean encode) +170
   System.Web.UI.WebControls.BaseValidator.AddAttributesToRender(HtmlTextWriter writer) +330
   System.Web.UI.WebControls.RequiredFieldValidator.AddAttributesToRender(HtmlTextWriter writer) +18
   System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +20
   System.Web.UI.WebControls.BaseValidator.Render(HtmlTextWriter writer) +445
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter writer) +57
   System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27

在渲染表控件之前,Validator控件需要删除或需要设置visible = false



请参考: http://forums.asp.net/t/ 1632629.aspx / 1 [ ^ ]网站。
Before rendering the table control the Validator controls need to remove or need to set "visible=false"

Please refere: http://forums.asp.net/t/1632629.aspx/1[^] site.