Is there a way to simulate an asp.net button.click event to fire when enter is pressed "anywhere" on a web page
Is there a way to simulate an asp.net button.click event to fire when enter is pressed on the screen.
As this is in theory a relativly small amount code involved may i request a working exmaple/or code samples.
Thanks
Webbo
NB: settng focus on the button isnt an option as the page this is used on is highly interactive, and i'm guessing js will need to be used.
ASP.NETJavaScript
Last Comment
rajapandian_81
8/22/2022 - Mon
Bardobrave
Well... I'm not sure if this is exactly what you need, but you can attack via JavaScript an onKeyPress event to <BODY> tag on your page, and when the pressed key is "INTRO" you can fire your click button.
If you use jquery (wich I highly recommend for web development) the attach event will be something like:
$("body").keypress(function (event) {
if (event.keycode == 13)
$("#myNETButton").click();
});
Is it a client button or an ASP.net server button control? Do you want only the client javascript code of the button (if it has someone) to be executed or also the server button's code?
If you use jquery (wich I highly recommend for web development) the attach event will be something like:
$("body").keypress(functio
if (event.keycode == 13)
$("#myNETButton").click();
});