I want to disable the enter key on a particular page created on sh开发者_StackOverflow中文版arepoint 2010 site. The reason behind this is ...on this page I have deployed a single web part with many server controls, textbox, dropdowns etc. Whenever I click on these server controls or anywhere on the page , it enables the submit button.
Is there any way to achieve this, I tried to disable teh enter key on all teh web controls it works, but if I click apart from these web controls it does not.
I have used the below function for specifix textboxes etc.
textbox1.Attributes.Add("onkeypress", "return DisableEnterKey(event);");
function DisableEnterKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode == 13)
{
return false;
}
return true;
}
Any help would be appreciated.
There's some quirky behavior to enter-key submissions having to do with which controls are on (or missing from) your page.
I think asp.net lets you explicitly set a 'default button' attribute in the form tag (and also panel tags).
<form id="form_1" runat="server" defaultbutton="my_button1">
or
<asp:Panel ID="pnl_1" runat="server" defaultbutton="my_button2">
So one idea might be to set the default_button to some invisible, do-nothing button. (or maybe you'd make it set the focus to one of your other controls...)
精彩评论