Enter Key in aspx page

P

Purvi T

Hi,

I am trying to do the enter-key capture in an aspx page. Since I wanted to
use a common function in all my forms, I wrote a function as shown. I call
this function on the textbox onkeydown by adding attribute as follows in the
c# code behind file.
txtUserID.Attributes.Add("onkeydown","LoginEnter(event,'btnLogin')");

The problem arises when the autofill option of forms is on in IE Browser. In
this case, after i use the arrow key to go to the option i want (from the
autofill entries that appear) and press enter, the function gets called. The
selected text does not appear in the text box.

I need to capture enter keys but without the occurence of the above problem.
Please help.

//***************************Start
function LoginEnter(ctrlName)

{

var keycode;


if (window.event)

{

keycode = window.event.keyCode;


}


if (keycode == 13)

{

document.getElementById(ctrlName).click();


}

event.returnValue = false;

}

}

//***************************End


Purvi
 
P

Purvi Thacker

Hi,
Thanks for your help, i could get it working.
However there is a problem on some pages where I have an image button
within a user control on the same page (for a search option on the
header bar). If i press enter, then the click event of the image button
gets called. Any idea how to get around this?

Purvi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top