I have a submit button and back button in my asp.net webform. I need to use the submit button when pressing enter, but it's going to the back button instead.
Please help...
I have a submit button and back button in my asp.net webform. I need to use the submit button when pressing enter, but it's going to the back button instead.
Please help...
Wrap your section in a Panel - then you can use the DefaultButton property to set your submit button to be the default when enter is pressed.
<asp:Panel runat="server" ID="MyPanel" DefaultButton="MySubmitButton">
... put your form here
<asp:Button runat="server" ID="MyCancelButton" Text="Cancel" />
<asp:Button runat="server" ID="MySubmitButton" Text="Submit" />
</asp:Panel>
You need to set the default button for you form or panel
<form id="form1" runat="server" defaultbutton="MySubmitButton">
Or intercept the key presses in JS:
Example uses YUI to help :)
YAHOO.util.Event.onDOMReady(function() {
YAHOO.util.Event.addListener(document, "keydown", enterKeyPress);
});
function enterKeyPress(ev) {
ev || (ev = window.event);
var code = (ev.keyCode ? ev.keyCode : (ev.charCode ? ev.charCode : ev.which));
// pressed ENTER get TAB
if (code == 13) {
try {
var button = document.getElementById("you button client id");
if (button != null) button.click();
}
catch (Error) {
logError(Error);
}
YAHOO.util.Event.preventDefault(ev);
}
}