Enter Key == Submit/Default button - but which one!

D

David Laub

I've noticed pressing the Enter key on a web form mimics pressing the
"default" button. But in asp.net, there is no definition of a default
button - all asp.net web control buttons become HTML submit buttons, which
is fine, but which one is the ONE and ONLY "default" button that is clicked
implicitly by pressing Enter?

is it the first button you draw on the form? How do you change it to be
another button?

Specifically, I want the Enter key (or at least I don't mind) the Enter key
to implicitly be my "Next" page button, but not my "Previous" page button

Thanks

David Laub
 
E

Eidolon

This is a bugger of a mess they did with the enter key. What you can do
though is make some client-side scripting, as such:

<script>
function catchEnter(){
if(event.keyCode == 13)
__doPostBack('<%=myButton.ClientID%>','');
return false;
else
return true;
}
</script>

and set your body up as :

<body onkeydown="return catchEnter();">

Thats basically what you need to do. Ive found sometimes it takes a little
tinkering to get it just right, but it will eventually work.

Cheerz!
 
J

Jos

David said:
I've noticed pressing the Enter key on a web form mimics pressing the
"default" button. But in asp.net, there is no definition of a default
button - all asp.net web control buttons become HTML submit buttons,
which is fine, but which one is the ONE and ONLY "default" button
that is clicked implicitly by pressing Enter?

is it the first button you draw on the form? How do you change it to
be another button?

Specifically, I want the Enter key (or at least I don't mind) the
Enter key to implicitly be my "Next" page button, but not my
"Previous" page button

In addition to Eidolon's response:
It is the first submit button on the page which will be the default button.
This is an HTML issue, not an ASP.NET one (but of course, ASP.NET
contributes by creating multiple submit buttons).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top