Hi Walter,
I made some progress on this issue. I finally found a workaround.
Please find below my comments.
> I can now see the issue you mentioned clearly. However, I don't think this
> issue is related to asp.net at all: consider following simple html page:
[quoted text clipped - 14 lines]
> Try this html page in IE and FireFox, you will see when you click on the
> div and press any key, FireFox will not show a messagebox.
Indeed, but here you use the 'onkeydown' html element attribute.
You will find below the code of an html page that basically does what
the MS Ajax library is doing at init time using the DOM API.
As it is, it reproduces the behavior I have with MS js lib.
That is, the keydown event handler is not called.
Doing more tests, I found that in order to the key event handler is
called under Firefox, the div elt must have its 'tabIndex' property set
to -1.
In this case, the keyboard event handlers are called as expected, as under
IE.
(To see the fixed behavior in the sample below, uncomment the line
"elt.tabIndex = -1;").
I don't know whether such a workaround could be integrated into the MS ajax
js
library, as it might be too intrusive, and whether it is a bug or not.
I really don't know so I let you decide what to do with that. On my side,
the fix is easy and the issue is fixed.
> By the way, you should always use ClientID when generating client-side
> content, which means you need to change the code in your OnRenderControl
> to:
>
> writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
Yes, thanks. It seems I wrote my sample too fast :-)
Thanks for your help,
Patrick
Patrick Ruzand - 15 Mar 2007 15:18 GMT
> Hi Walter,
>
> I made some progress on this issue. I finally found a workaround.
> Please find below my comments.
[...]
> You will find below the code of an html page that basically does what
> the MS Ajax library is doing at init time using the DOM API.
> As it is, it reproduces the behavior I have with MS js lib.
it's better with the code...
---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<script type="text/javascript">
function wireEventHandler(target, eventName, handler) {
var elt = document.getElementById(target);
if (elt.addEventListener) {
// Begin Firefox workaround
// *** Uncomment the line below to fix the issue ***
// elt.tabIndex = -1;
// End Firefox workaround
elt.addEventListener(eventName, handler, true);
}
}
function foo(e) {
alert('onkeydown: ' + e.target.id);
}
</script>
<input type="text" id="text" />
<div id="mydiv" style="width:100px;height:100px;background-color:blue"
></div>
<div style="left: 5px; width: 500px; position: absolute; top: 105px; height:
500px">
<div id="MyControl1"
style="background-color:red;position:relative;left:5px;top:5px;width:500px;height:500px;">
</div>
</div>
<script type="text/javascript">
wireEventHandler('MyControl1','keydown', foo);
</script>
</body>
</html>