System.ArgumentException: Item has already been added. Key in dictionary: 'language' Key being added: 'language' at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)

I have a web application in which I have a grid view.
Whenever I try to perform delete/ add/ modify operation on the grid view on a button click, I get following error:

2       System.ArgumentException: Item has already been added. Key in dictionary: 'language' Key being added: 'language'
3       at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
4       at System.Collections.Hashtable.Add(Object key, Object value)
5       at System.Collections.Specialized.OrderedDictionary.Add(Object key, Object value)
6       at System.Web.UI.ScriptRegistrationManager.WriteScriptWithTags(HtmlTextWriter writer, String token, RegisteredScript        activeRegistration)
7       at System.Web.UI.ScriptRegistrationManager.RenderActiveScriptBlocks(List`1 updatePanels, HtmlTextWriter writer, String token,        List`1 scriptRegistrations)
8       at System.Web.UI.ScriptRegistrationManager.RenderActiveScripts(List`1 updatePanels, HtmlTextWriter writer)
9       at System.Web.UI.PageRequestManager.ProcessScriptRegistration(HtmlTextWriter writer)
10       at System.Web.UI.PageRequestManager.RenderPageCallback(HtmlTextWriter writer, Control pageControl)
11       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
12       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
13       at System.Web.UI.Page.Render(HtmlTextWriter writer)
14       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
15       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
16       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
17       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Please see the attachments for the .aspx and .aspx.cs code

please help! Course-Schedule-aspx.txt Course-Schedule-aspx-cs.txt
Who is Participating?
sybeConnect With a Mentor Commented:
The only possible cause I can see is at line 154, where you have two attributes called "language"

GlobalClass.JScript_Alert = @"<script language='javascript' language='javascript'
Could you try to give unique Id while registering the script through Scriptmanager

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script1"

some of the Id's are repeated in more than one place
Tina_BholeAuthor Commented:
Hi santhimurthyd,

Thanks for your response.
I tried giving unique ids to the script blocks. It didn't help.
santhimurthydConnect With a Mentor Commented:
In addition to that the alert message with Javascript are not enclosed

Your syntax
GlobalClass.JScript_Alert = @"<script language='javascript'>alert(" + exp.ToString() + ");</script>";

Have to be
GlobalClass.JScript_Alert = @"<script language='javascript'>alert('" + exp.ToString() + "');</script>";

Some more places, you need to consider he above syntax like

In yours
e.Row.Attributes["onclick"] = "CourseScheduleGV_selectRow(this," + e.Row.RowIndex + ");";

have to be
e.Row.Attributes["onclick"] = "CourseScheduleGV_selectRow(this,'" + e.Row.RowIndex + "');

In the Method
protected void SaveRecord(object sender, EventArgs e)

As mentioned by sybe
there are couple of syntax with dual entry for  language='javascript'

GlobalClass.JScript_Alert = @"<script language='javascript' language='javascript' type='text/javascript'>alert('Please Enter the Course Schedule Details.');</script>";

GlobalClass.JScript_Alert = @"<script language='javascript' language='javascript' type='text/javascript'>alert('Course End Date cannot be greater than Course Start Date');</script>";

lobalClass.JScript_Alert = @"<script language='javascript' language='javascript' type='text/javascript'>alert('Course End Date cannot be greater than Course Start Date');</script>";

please let you outcoem after the above changes

Tina_BholeAuthor Commented:
Thanks for helping Santhimurthyd and sybe.
Yes, making use of language='javascript' was itself a big mistake I made because the language attribute has been deprecated. I used type='text/javascript' instead of language.

@ santhimurthyd : the application is working perfectly fine without changing
"CourseScheduleGV_selectRow(this," + e.Row.RowIndex + ");";
"CourseScheduleGV_selectRow(this,'" + e.Row.RowIndex + "');
So, for the time being, I have left it as it is.

Thanks a lot once again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.