While I don't have an exact answer, it may be because the event is occurring in the IFrame which has its own DOM, eventing model, etc. The IFrame document really acts independently of the parent page. It is its own document with its own window, etc. Passing
an event from the IFrame to the parent window is probably not supported in the framework as it's impossible for the framework to know how many levels deep the event is (an Iframe inside of an IFrame, inside of an IFrame, etc.).
I kind of ran into this before when trying to work with multiple modal popups that contained IFrames.
hi, this is indeed a bug. If you will note the code for addHandler method in the ajax extentions library, you will note that the window object is hard coded, which makes it choke in IE if your trying to attach events to elements in your iframe. The ideal
solution is to have a 4th parameter on the addHandler method that takes a window object and the problem is resolved. Note below the code in addHandler :
if (element.attachEvent) {
browserHandler = function() {
return handler.call(element, new Sys.UI.DomEvent(window.event));
}
Note above the window object hardcoded and passed to DomEvent class. This is why we all have problems when we use iframe ;-)
I hope the asp.net team update the ajax libraries addHandler method with a forth parameter. In the meantime, i have prototyped a addHandler2 method which can take a forth parameter. in the forth parameter pass it the window object of your iframe, that will be contentWindow. Following is the prototype :
Sys.UI.DomEvent.addHandler2 = function Sys$UI$DomEvent$addHandler(element, eventName, handler, contentWindow) {
/// <param name="element" domElement="true"></param>
/// <param name="eventName" type="String"></param>
/// <param name="handler" type="Function"></param>
var e = Function._validateParams(arguments, [
{name: "element", domElement: true},
{name: "eventName", type: String},
{name: "handler", type: Function},
{name: "contentWindow", type: Object, optional: true, mayBeNull: true}
]);
if (e) throw e;
if (!element._events) {
element._events = {};
}
var eventCache = element._events[eventName];
if (!eventCache) {
element._events[eventName] = eventCache = [];
}
var browserHandler;
if (element.addEventListener) {
browserHandler = function(e) {
return handler.call(element, new Sys.UI.DomEvent(e));
}
element.addEventListener(eventName, browserHandler, false);
}
else if (element.attachEvent) {
browserHandler = function() {
var w = (contentWindow == null) ? window.event : contentWindow
return handler.call(element, new Sys.UI.DomEvent(w.event));
}
element.attachEvent('on' + eventName, browserHandler);
}
eventCache[eventCache.length] = {handler: handler, browserHandler: browserHandler};
}
Just ran into this today, doing the exact same thing, referencing an upload form in an iframe. Works in FF, not in IE. Alessandro, thanks for the summary and code.
Thanks for the code. Were you ever able to get this to work in IE? It only works in FF for me.
hi, yes ofcourse. The whole point of the prototype is to get it working in IE. You need to pass the fourth parameter in the prototyped function. This parameter must be your iframes contentWindow.
jlchereau
Member
91 Points
25 Posts
Bug with $addHandler applied to element in an iFrame
Oct 22, 2006 08:17 PM|LINK
I have two pages:
In my first page, I have a pageLoad function which contains the following script:
g_UploadIFrame = $get("iframeFileUpload"); <% //Reference to the iFrame element %>
g_FileUploadTextBox = $get("FileUpload", g_UploadIFrame.contentWindow.document); <% //Reference to the File input field%>
$addHandler(g_FileUploadTextBox, "keyup", validateBeforeSend);
$addHandler(g_FileUploadTextBox, "propertychange", validateBeforeSend);
where g_UploadIFrame and g_FileUploadTextBox are declared globally and validateBeforeSend displays an alert for the purpose of this report.
This code executes fine when the page loads but raises the following error when the event is raised:
Line 2089 Char 12: Sys.ArgumentNullException: Value cannot be null. Parameter name: eventObject.
jlchereau
Member
91 Points
25 Posts
Re: Bug with $addHandler applied to element in an iFrame
Oct 23, 2006 12:16 PM|LINK
JRumerman
Member
585 Points
140 Posts
Re: Bug with $addHandler applied to element in an iFrame
Oct 27, 2006 05:17 AM|LINK
While I don't have an exact answer, it may be because the event is occurring in the IFrame which has its own DOM, eventing model, etc. The IFrame document really acts independently of the parent page. It is its own document with its own window, etc. Passing an event from the IFrame to the parent window is probably not supported in the framework as it's impossible for the framework to know how many levels deep the event is (an Iframe inside of an IFrame, inside of an IFrame, etc.).
I kind of ran into this before when trying to work with multiple modal popups that contained IFrames.
Hope this helps.
* My Blog
* Advanced ASP.NET AJAX Server Controls
martijnvm
Member
11 Points
51 Posts
Re: Bug with $addHandler applied to element in an iFrame
Apr 06, 2007 10:40 AM|LINK
martijnvm
Member
11 Points
51 Posts
Re: Bug with $addHandler applied to element in an iFrame
Apr 10, 2007 07:40 AM|LINK
Anybody who has a fix or workaround for this? Please let me know.
Thanks
alessandro
Contributor
6800 Points
1105 Posts
Re: Bug with $addHandler applied to element in an iFrame
May 18, 2007 04:05 PM|LINK
hi, this is indeed a bug. If you will note the code for addHandler method in the ajax extentions library, you will note that the window object is hard coded, which makes it choke in IE if your trying to attach events to elements in your iframe. The ideal solution is to have a 4th parameter on the addHandler method that takes a window object and the problem is resolved. Note below the code in addHandler :
if (element.attachEvent) { browserHandler = function() { return handler.call(element, new Sys.UI.DomEvent(window.event)); }Note above the window object hardcoded and passed to DomEvent class. This is why we all have problems when we use iframe ;-)
I hope the asp.net team update the ajax libraries addHandler method with a forth parameter. In the meantime, i have prototyped a addHandler2 method which can take a forth parameter. in the forth parameter pass it the window object of your iframe, that will be contentWindow. Following is the prototype :
Sys.UI.DomEvent.addHandler2 = function Sys$UI$DomEvent$addHandler(element, eventName, handler, contentWindow) { /// <param name="element" domElement="true"></param> /// <param name="eventName" type="String"></param> /// <param name="handler" type="Function"></param> var e = Function._validateParams(arguments, [ {name: "element", domElement: true}, {name: "eventName", type: String}, {name: "handler", type: Function}, {name: "contentWindow", type: Object, optional: true, mayBeNull: true} ]); if (e) throw e; if (!element._events) { element._events = {}; } var eventCache = element._events[eventName]; if (!eventCache) { element._events[eventName] = eventCache = []; } var browserHandler; if (element.addEventListener) { browserHandler = function(e) { return handler.call(element, new Sys.UI.DomEvent(e)); } element.addEventListener(eventName, browserHandler, false); } else if (element.attachEvent) { browserHandler = function() { var w = (contentWindow == null) ? window.event : contentWindow return handler.call(element, new Sys.UI.DomEvent(w.event)); } element.attachEvent('on' + eventName, browserHandler); } eventCache[eventCache.length] = {handler: handler, browserHandler: browserHandler}; }good luck
freelancer
Member
49 Points
15 Posts
Re: Bug with $addHandler applied to element in an iFrame
Dec 05, 2007 09:55 PM|LINK
Just ran into this today, doing the exact same thing, referencing an upload form in an iframe. Works in FF, not in IE. Alessandro, thanks for the summary and code.
iframe upload
JChung2007
Member
14 Points
2 Posts
Re: Bug with $addHandler applied to element in an iFrame
Jan 17, 2008 11:36 AM|LINK
EDIT: My proposed alternative didn't work. Sorry.
mbonano
Member
6 Points
3 Posts
Re: Bug with $addHandler applied to element in an iFrame
Jan 17, 2008 03:11 PM|LINK
Thanks for the code. Were you ever able to get this to work in IE? It only works in FF for me.
alessandro
Contributor
6800 Points
1105 Posts
Re: Bug with $addHandler applied to element in an iFrame
Jan 17, 2008 03:57 PM|LINK
hi, yes ofcourse. The whole point of the prototype is to get it working in IE. You need to pass the fourth parameter in the prototyped function. This parameter must be your iframes contentWindow.
Good luck,
Alessandro