Sep 22, 2009

How to raise a button click event on Enter keypress

Button click on Enter :

On client side:

// To perform button click operation on enter.

function doClick(buttonName, e) {

//the purpose of this function is to allow the enter key to

//point to the correct button to click.

var key;

if (window.event)

key = window.event.keyCode; //IE


key = e.which; //firefox

if (key == 13) {

//Get the button the user wants to have clicked

var btn = document.getElementById(buttonName);

if (btn != null) { //If we find the button click it;

event.keyCode = 0



On server side :
on server side we have to specify that the click should happen only when the cursor is on certain text box.
txtRadNZoomValue.Attributes.Add("onKeyPress", "doClick('" + btnZoomValue.ClientID + "',event)");

No comments: