Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Is there a way to simulate an asp.net button.click event to fire when enter is pressed "anywhere" on a web page

Posted on 2010-09-09
5
Medium Priority
?
442 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:Webbo_1980
5 Comments
 
LVL 19

Expert Comment

by:Bardobrave
ID: 33634987
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();
});
0
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 33635171
Set defaultbutton property of page.

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

OR

Page.Form.DefaultButton = btnSubmit.UniqueID;
0
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 33635203
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?
0
 

Author Comment

by:Webbo_1980
ID: 33635462
hi all few questions...

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

RolandDeschain: to anwser your question it an asp.net server side control, and i need the server side code to run not the js
0
 
LVL 12

Accepted Solution

by:
rajapandian_81 earned 2000 total points
ID: 33635626
Webbo_1980:

Normally defaultbutton will be "first button" available in the page. Whenever enter is pressed from keyboard that first button event will be triggered. My code will change the default button to "user defined button".

It will not affect any other things.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question