469,609 Members | 2,141 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

How to set onclick for default button

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
4 4725
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
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
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
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.

Similar topics

3 posts views Thread by Stefan Finzel | last post: by
10 posts views Thread by drawde83 | last post: by
2 posts views Thread by Sedef | last post: by
2 posts views Thread by Lenard Gunda | last post: by
2 posts views Thread by moondaddy | last post: by
4 posts views Thread by sameergn | last post: by
3 posts views Thread by Harry Haller | last post: by
5 posts views Thread by GiJeet | last post: by
18 posts views Thread by navyjax2 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.