Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have two textboxes and two button
Now if i enter some text in first textbox and press enter key then first button is firing.
if i enter some text in second textbox and press enter key then first button is firing but I want to fire second button.

Please let me know how to implement it.

Thanking you
mohd wasif
Posted

You can do like that
function button1()
{
    document.getElementById('<%= Button1.ClientID%>').focus()
}
function button2()
{
    document.getElementById('<%= Button2.ClientID%>').focus()
}

and call these functions on "onblur" event of the textbox like
<asp:textbox id="TextBox1" runat="server" onblur="button1()" xmlns:asp="#unknown" />
 
Share this answer
 
Comments
Sandeep Mewara 27-Apr-11 9:54am    
My 5!
nit_singh 27-Apr-11 10:03am    
Thanks Sandeep
Write a JavaScript function and handle the keyup event of the textbox. Check if the KeyCode is 13 (i.e) enter button is pressed, call the corresponding button click event.

Give it a try!
 
Share this answer
 
Comments
Monjurul Habib 27-Apr-11 15:05pm    
nice advice. my 5.
Ankur\m/ 28-Apr-11 0:09am    
Thanks Monjurul!
If you want to press enter in a textbox - see below - vb.net

Let's say that button2 has the code you want to call - by pressing enter in a textbox

This is an easy way to do it

notice - Textbox1_keydown
VB
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
   If (e.KeyCode = Keys.Enter) Then Button2.PerformClick()
End Sub
 
Share this answer
 
v2
Comments
Sandeep Mewara 14-Oct-12 10:50am    
1. You answer a 1+ year old post
2. It's clearly mentioned as ASP.NET and you give a winforms reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900