Showing posts with label enter. Show all posts
Showing posts with label enter. Show all posts

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.

Default Button in master pages - using Ajax

Hi,

My application uses master pages and now recently am using Ajax features. I wanted to handle the enter click in search pages. So i used the defaultbutton property of the page that sets to the control id which we specify when enter is clicked.

But the problem i have is when the focus of the cursor is on another button and i click enter from keyboard it still fires the search event instead of the buttons event.

Can someone explain the behaviour.

Thanks in advance.

Regards,

Rajesh

Setting the default button does just that... sets the default button that gets clicked when the enter key is pressed while on the page. Therefore, no matter what other button has focus on the page, hitting enter fires off the default.