I've inherited some code that is having a serious problem. On one page, there are several pairs of "Yes"/"No" checkboxes that act like pairs of radio buttons through the use of the ACT MutuallyExclusiveCheckBoxExtender control. They work as expected. However,
when I navigate away from the page, I get a "Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method." error in the dynamically-generated ScriptResource.ax...c2d9970 [dynamic]
file. The specific method in the dynamically-generated code is:
var $removeHandler = Sys.UI.DomEvent.removeHandler = function Sys$UI$DomEvent$removeHandler(element, eventName, handler)
The element is set to any of the checkbox controls (I've removed them one-by-one and it happens to ALLof them) and the eventName is "Click". I gather from the code that it's trying to do a removeHandler before the addHandler for the particular element has
taken place. True, I don't have any explicit addHandler lines in my code, but I don't any explicit removeHandler lines either. About all I've got in the aspx code is:
The formatting of the code in this message is a bit weird, but it's basically a simple table with three columns. On each row, there's text in the first column, the checkboxes in the second column and a button in the third.
I've searched high and low on the web and nearly every thread I read about his error talks about it in relationship to the use of command buttons in an ACT UpdatePanel.
3. After initializeBase(this, [element]);
declare and initialize the eventhandler this._closeNow = null;
4. inside initialize: function()
before i was using $addHandlers
replaced it with seperate $addHandler for each event like the following this._closeNow = Function.createDelegate(this, this._onCloseNow);
$addHandler(this._closeImage, "click", this._closeNow);
5. inside dispose: function()
before i was using $clearHandlers(this.get_element()); to clear the events
replaced it with seperate $removeHandler for each event thati added in the initialize function like the following if (this._closeNow)
{
//alert(this._closeNow);
$removeHandler(this._closeImage, "click", this._closeNow);
this._closeNow = null;
}
6. clear the cache of the IE and run it and problem solved.
Forgive an old desktop app developer who's struggling to convert over to web apps, but this looks more like JavaScript to me than the HTML/XML of the aspx files or the C# of the aspx.cs files that I have in my app. I haven't written ANY JavaScript for this
app; it's all C#. The controls that seem to be related to the issues were drag-and-dropped onto the interface and were either standard web controls (the checkboxes) or Ajax Toolkit Controls (the MutuallyExclusiveCheckbBoxExtender). I'm sure that the Ajax Toolkit
Controls use JavaScript "under the covers", but I have no idea where I'd add the code referenced above into my application code. Is there something I'm supposed to be adding to the code other than the reference to the AjaxControlToolkit assembly?
Do you have any reference on why this error occurs and it is fixed by changing ScriptMode? It didn't occur to me until we made some changes but I am unable to identify the cause.
JerryLBell
0 Points
2 Posts
"Handler was not added through the Sys.UI.DomEvent.addHandler method error" with checkbox and Mut...
Aug 18, 2010 08:41 PM|LINK
I've inherited some code that is having a serious problem. On one page, there are several pairs of "Yes"/"No" checkboxes that act like pairs of radio buttons through the use of the ACT MutuallyExclusiveCheckBoxExtender control. They work as expected. However, when I navigate away from the page, I get a "Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method." error in the dynamically-generated ScriptResource.ax...c2d9970 [dynamic] file. The specific method in the dynamically-generated code is:
var $removeHandler = Sys.UI.DomEvent.removeHandler = function Sys$UI$DomEvent$removeHandler(element, eventName, handler)
The element is set to any of the checkbox controls (I've removed them one-by-one and it happens to ALLof them) and the eventName is "Click". I gather from the code that it's trying to do a removeHandler before the addHandler for the particular element has taken place. True, I don't have any explicit addHandler lines in my code, but I don't any explicit removeHandler lines either. About all I've got in the aspx code is:
<
td class="td_black_Text_Label" align="left" colspan="1">
<asp:CheckBox ID="cbPYes" runat="server" Text="Yes" AutoPostBack="true" OnCheckedChanged="CheckChanged"/> <asp:CheckBox ID="cbPNo" runat="server" Text="No" AutoPostBack="true" OnCheckedChanged="CheckChanged"/>
<tk:MutuallyExclusiveCheckBoxExtender
runat="server" ID="MutuallyExclusiveCheckBoxExtender3" TargetControlID="cbPYes" Key="Pharmacy"> </tk:MutuallyExclusiveCheckBoxExtender>
<tk:MutuallyExclusiveCheckBoxExtender runat="server" ID="MutuallyExclusiveCheckBoxExtender4" TargetControlID="cbPNo" Key="Pharmacy">
</tk:MutuallyExclusiveCheckBoxExtender>
</td>
<td>
<asp:button CommandName="PharmacySetup" id="btnPharmacySetup" Text="Pharmacy Setup" style="font-style:italic" runat="server" OnCommand="CommandClick" />
</td>The formatting of the code in this message is a bit weird, but it's basically a simple table with three columns. On each row, there's text in the first column, the checkboxes in the second column and a button in the third.
I've searched high and low on the web and nearly every thread I read about his error talks about it in relationship to the use of command buttons in an ACT UpdatePanel.
Any help would be greatly appreciated!
Jerry
MutuallyExclusiveCheckBoxExtender ToggleButtonExtender addHandler
chetan.sarod...
All-Star
65759 Points
11153 Posts
Re: "Handler was not added through the Sys.UI.DomEvent.addHandler method error" with checkbox and...
Aug 19, 2010 03:30 AM|LINK
Please refer this
http://geekswithblogs.net/kazimmehdi/archive/2010/01/13/sys.invalidoperationexception-handler-was-not-added-through-the-sys.ui.domevent.addhandler-method.aspx
http://forums.asp.net/t/1484605.aspx
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
JerryLBell
0 Points
2 Posts
Re: "Handler was not added through the Sys.UI.DomEvent.addHandler method error" with checkbox and...
Aug 19, 2010 06:07 PM|LINK
I checked your link and it boils down to this:
3. After initializeBase(this, [element]);
declare and initialize the eventhandler
this._closeNow = null;
4. inside initialize: function()
before i was using $addHandlers
replaced it with seperate $addHandler for each event like the following
this._closeNow = Function.createDelegate(this, this._onCloseNow);
$addHandler(this._closeImage, "click", this._closeNow);
5. inside dispose: function()
before i was using $clearHandlers(this.get_element()); to clear the events
replaced it with seperate $removeHandler for each event thati added in the initialize function like the following
if (this._closeNow)
{
//alert(this._closeNow);
$removeHandler(this._closeImage, "click", this._closeNow);
this._closeNow = null;
}
6. clear the cache of the IE and run it and problem solved.
Forgive an old desktop app developer who's struggling to convert over to web apps, but this looks more like JavaScript to me than the HTML/XML of the aspx files or the C# of the aspx.cs files that I have in my app. I haven't written ANY JavaScript for this app; it's all C#. The controls that seem to be related to the issues were drag-and-dropped onto the interface and were either standard web controls (the checkboxes) or Ajax Toolkit Controls (the MutuallyExclusiveCheckbBoxExtender). I'm sure that the Ajax Toolkit Controls use JavaScript "under the covers", but I have no idea where I'd add the code referenced above into my application code. Is there something I'm supposed to be adding to the code other than the reference to the AjaxControlToolkit assembly?
Thanks in advance for any helpful replies!
tanajichavan
Member
4 Points
5 Posts
Re: "Handler was not added through the Sys.UI.DomEvent.addHandler method error" with checkbox and...
Sep 06, 2011 07:31 AM|LINK
set ScriptMode="Release" for script manager and let me know if it works.
gracianow
Member
2 Points
1 Post
Re: "Handler was not added through the Sys.UI.DomEvent.addHandler method error" with checkbox and...
Sep 20, 2011 10:04 AM|LINK
Congratulations, tanajichavan. Su respuesta me salió muy buena y ha solucionado mi problema.
suryakant4it
Member
51 Points
59 Posts
Re: "Handler was not added through the Sys.UI.DomEvent.addHandler method error" with checkbox and...
Jul 06, 2012 10:36 AM|LINK
It solved my problem.thanks
Johann87
Member
2 Points
1 Post
Re: "Handler was not added through the Sys.UI.DomEvent.addHandler method error" with checkbox and...
Jul 30, 2012 01:22 PM|LINK
Do you have any reference on why this error occurs and it is fixed by changing ScriptMode? It didn't occur to me until we made some changes but I am unable to identify the cause.
Thanks.