Link to home
Create AccountLog in
Avatar of Webbo_1980

asked on

Is there a way to simulate an event to fire when enter is pressed "anywhere" on a web page

Is there a way to simulate an 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.


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.
Avatar of Bardobrave
Flag of Spain image

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)
Set defaultbutton property of page.

<form id="form1" runat="server" defaultbutton="btnSubmit">


Page.Form.DefaultButton = btnSubmit.UniqueID;
Avatar of Luis Pérez
Is it a client button or an 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?
Avatar of Webbo_1980


hi all few questions...

rajapandian_81:if i set this, will all other postbacks work as normal?

RolandDeschain: to anwser your question it an server side control, and i need the server side code to run not the js
Avatar of rajapandian_81
Flag of India image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account