I have an asp form which has 3 text box and and a asp link button control.I want to invoke the button click event handler method when the user press enter key.I used asp panel and its default button property.Its working in IE.But not in other Browsers like firefox etc.. Is there any other method to do so ?
I have an asp form which has 3 text box and and a asp link button control.I want to invoke the button click event handler method when the user press enter key.I used asp panel and its default button property.Its working in IE.But not in other Browsers like firefox etc.. Is there any other method to do so ?
You could try the DefaultButton Property (ASP.Net 2.0 and above). The ASP.Net Form and Panel controls both have a DefaultButton Property. The default action means the enter key should trigger the button click.
<form id="Form1" defaultbutton="SubmitButton" runat="server">
<asp:panel id="panel1" defaultbutton="anotherbutton" runat="server">
</asp:panel>
</form>
There is a known FireFox issue that may be resolved by adding: UseSubmitBehavior="False"
to your submit button. This Blog describes the problem and solution in an UpdatePanel, it might work here as well.
Also check this question which has links to other possible solutions.
This seems to be a bug with FF3 (not sure), but the script that fixed is given below
Keep it at the end of the page so that it overrides the WebForm_FireDefaultButton method rendered by ASP.NET.
var __defaultFired = false;
function WebForm_FireDefaultButton(event, target) { var element = event.target || event.srcElement;
if (!__defaultFired && event.keyCode == 13 && !(element && (element.tagName.toLowerCase() == "textarea"))) {
var defaultButton;
if (__nonMSDOMBrowser)
defaultButton = document.getElementById(target);
else
defaultButton = document.all[target];
if (defaultButton) {
if(typeof(defaultButton.click) != "undefined")
defaultButton.click();
else
eval(unescape(defaultButton.href.replace("javascript:", "")));
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
return false;
}
}
return true;
}