Wednesday, March 21, 2012

DefaultButton in Firefox

I added a DefaultButtion to a normal asp panel to handle enter key event. This works fine in IE, but has problem in FireFox.

This asp panel is in anupdate panel.

When user presses enter key in FireFox, this does not trigger OnClick function of the button, it only triggers client side function OnClientClick. My submit button code is in server side OnClick function. So when user presses the enter key, nothing is saved.

I debugged the javascript, traced to following function:

function WebForm_FireDefaultButton(event, target) {
if (event.keyCode == 13 &&
!(event.srcElement &&
event.srcElement.tagName.toLowerCase() == "textarea")) {
var defaultButton;
if (__nonMSDOMBrowser) {
defaultButton = document.getElementById(target);
} else {
defaultButton = document.all[target];
}
if (defaultButton && typeof defaultButton.click != "undefined") {
defaultButton.click(); myapplication continues. But web application which does not use Ajax stops here and posts back. ?
event.cancelBubble = true;
if (event.stopPropagation) {
event.stopPropagation();
}
return false;
}
}
return true;
}

Is this problem related to update panel. I used the approach inhttp://forums.asp.net/thread/1685533.aspx. (UseSubmitBehavior="False" OnClientClick="ResetDefault" ).But that does not work.

Any suggestion will be much appreciated.

Any luck with this issue? Sounds like I have the same issue as you and I also tried the ResetDefault function with no luck. I reset the __defaultFired variable (i think that's the name of it) inside the page_prerender using the registerclientstartupscript method with no luck. I noticed that the the enter button does cause a postback, it just doesn't fire the button that it is suppose to be firing. If you look at the Request.Forms collection the button is missing from it. If you look at the same collection after clicking the button with the mouse it is there. I hope someone can shed a little light on this matter. I am going to try to create a simple page to reproduce the issue.

No comments:

Post a Comment