By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,530 Members | 2,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,530 IT Pros & Developers. It's quick & easy.

How to set onclick for default button

P: n/a
RA
Hi

I have asp.net web app. When a user clicks the enter key when he is viewing
the aspx web form, it jumps to the starting web form. How can I handle the
user hitting the enter key and to redirect it to a default button. So lets
say that I have a button name - Submit - if the user clicks anywhere in the
form on the enter key I want it to default to a click on the 'Submit' button
which is an asp.net button.
Thanks,
Ron
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Do this in you r/javascript function hooked to any where
on textbox etc.

function abc()
{
if(window.event.keyCode == '13')
{
document.getElementById(yoursubmitnuttonid).click
();
event.returnValue = false;
}
}

event.returnvalue is for avoiding beep sound.

Happy programming..
Ajay
-----Original Message-----
Hi

I have asp.net web app. When a user clicks the enter key when he is viewingthe aspx web form, it jumps to the starting web form. How can I handle theuser hitting the enter key and to redirect it to a default button. So letssay that I have a button name - Submit - if the user clicks anywhere in theform on the enter key I want it to default to a click on the 'Submit' buttonwhich is an asp.net button.
Thanks,
Ron
.

Nov 17 '05 #2

P: n/a
Do this in you r/javascript function hooked to any where
on textbox etc.

function abc()
{
if(window.event.keyCode == '13')
{
document.getElementById(yoursubmitnuttonid).click
();
event.returnValue = false;
}
}

event.returnvalue is for avoiding beep sound.

Happy programming..
Ajay
-----Original Message-----
Hi

I have asp.net web app. When a user clicks the enter key when he is viewingthe aspx web form, it jumps to the starting web form. How can I handle theuser hitting the enter key and to redirect it to a default button. So letssay that I have a button name - Submit - if the user clicks anywhere in theform on the enter key I want it to default to a click on the 'Submit' buttonwhich is an asp.net button.
Thanks,
Ron
.

Nov 17 '05 #3

P: n/a
You can intercept the client side enter keypress event of the text box and
then click do what you want using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx

And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"RA" <ro****@hotmail.com> wrote in message
news:Oi***************@TK2MSFTNGP10.phx.gbl...
Hi

I have asp.net web app. When a user clicks the enter key when he is viewing the aspx web form, it jumps to the starting web form. How can I handle the
user hitting the enter key and to redirect it to a default button. So lets
say that I have a button name - Submit - if the user clicks anywhere in the form on the enter key I want it to default to a click on the 'Submit' button which is an asp.net button.
Thanks,
Ron

Nov 17 '05 #4

P: n/a
You can intercept the client side enter keypress event of the text box and
then click do what you want using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx

And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"RA" <ro****@hotmail.com> wrote in message
news:Oi***************@TK2MSFTNGP10.phx.gbl...
Hi

I have asp.net web app. When a user clicks the enter key when he is viewing the aspx web form, it jumps to the starting web form. How can I handle the
user hitting the enter key and to redirect it to a default button. So lets
say that I have a button name - Submit - if the user clicks anywhere in the form on the enter key I want it to default to a click on the 'Submit' button which is an asp.net button.
Thanks,
Ron

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.