admin管理员组文章数量:1026989
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 ?
Share Improve this question edited May 7, 2011 at 17:56 Muhammad Akhtar 52.2k37 gold badges139 silver badges191 bronze badges asked Jun 20, 2009 at 10:28 ShyjuShyju 219k106 gold badges420 silver badges498 bronze badges2 Answers
Reset to default 3You 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;
}
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 ?
Share Improve this question edited May 7, 2011 at 17:56 Muhammad Akhtar 52.2k37 gold badges139 silver badges191 bronze badges asked Jun 20, 2009 at 10:28 ShyjuShyju 219k106 gold badges420 silver badges498 bronze badges2 Answers
Reset to default 3You 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;
}
本文标签: javascriptASPNETInvoke codebehind method on Enter Key press in formStack Overflow
版权声明:本文标题:javascript - ASP.NET : Invoke codebehind method on Enter Key press in form - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745665694a2162163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论