Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.

C#
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
Posted
Updated 13-Aug-13 5:17am
v3
Comments
TrushnaK 13-Aug-13 9:40am    
where you get this error?
prasy123 13-Aug-13 9:46am    
After the submit button click event the page showing this error.
OriginalGriff 13-Aug-13 9:55am    
No, we would need to see the code fragment generating the error...
prasy123 13-Aug-13 10:03am    
Dim tr As New TableRow()
Dim td1 As New TableCell()

Dim rfvCANnew As New RequiredFieldValidator
rfvCANnew.ID = "rfvCANnew" + i
rfvCANnew.ErrorMessage = "CAN Field is Required"
rfvCANnew.ValidationGroup = "grpSave"
rfvCANnew.ControlToValidate = drpCan.ID
rfvCANnew.InitialValue = 0
rfvCANnew.Display = ValidatorDisplay.None
rfvCANnew.SetFocusOnError = True

td1.Controls.Add(rfvCANnew)
tr.Cells.Add(td1)
tblNewCan.Rows.Add(tr)

// Also given increment for i in each row generation..

And I am using this table in the body of a mail by using the below code
Dim SBEoc As New StringBuilder()
Dim SWEoc As New StringWriter(SBEoc)
Dim htmlTWEoc As New HtmlTextWriter(SWEoc)
tblNewCan.RenderControl(htmlTWEoc)
sendEMailDraft(TableHTMLEoc)
prasy123 13-Aug-13 10:05am    
After adding this field validator making this exception otherwise that code was working fine

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900