How to identify the control when User uses the Enter Key

G

Guest

Hi

I am building a Search Interface.It has two text boxes (box1 and box2) and
two buttons (btnbox1 and btnbox2) in the ASPX page.

Example
User keys in a search text in box2 and presses the Enter key. How to
identify that page was submitted becoz the User pressed the enter key when he
was in box2.

Currently in the page load I see which box is empty and then take respective
action but this is not desirable.
Kindly let me if this can be achieved.

Regards
Vishwanathan
 
G

Guest

hi Vishwanathan,

If i understand your problem properly, you want click button 2 when user is
in box2 and press enter and same for text box 1/button 2 combination.

If this is the problem, then the solution is pretty simple.
server side:
textbox1.Attributes.add("onkeypress","ClickAddButton('button1');")
textbox2.Attributes.add("onkeypress","ClickAddButton('button2');")

Javascript:
function ClickAddButton(buttonId)
{
if(event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;

document.getElementById(buttonId).click();
}
}

regards
Ural
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top