Enter key association with multiple textboxes
-
So let's say I have a Search textbox on a page and a login textbox on a page. When I hit the enter key on the keyboard I want it to fire the login button click event when the cursor is in the login textbox and fire the search button click event when the cursor is in the search textbox. How does one handle that? I found some vague references in google about using javascript for this, but is there any C# asp.net native ways of doing this? If js is the only way can someone post an example or a good url of where this is covered? Thank you
-
So let's say I have a Search textbox on a page and a login textbox on a page. When I hit the enter key on the keyboard I want it to fire the login button click event when the cursor is in the login textbox and fire the search button click event when the cursor is in the search textbox. How does one handle that? I found some vague references in google about using javascript for this, but is there any C# asp.net native ways of doing this? If js is the only way can someone post an example or a good url of where this is covered? Thank you
u have to capture the key press event and you have to check the condition whether enter is pressed or not if pressed you have to dopostback on the control you want following the is the example to capture event. in you aspx page under the for tag place your text box in page load event write the following code If Not Me.IsPostBack() Then textBoxName.Attributes.Add("onKeyDown", "javascript:checkEvent();") End If in your aspx page under the HEAD tag write the following javascript code function checkEvent() { alert(window.event.keyCode); if (window.event.keyCode==13) { __doPostBack("controlname",""); //please check the code i used to do like this only make sure view state of your control is true this is code i have used and it is working fone for me } }
Thanks Warm Regards Prakash-B