Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Enter key association with multiple textboxes

Enter key association with multiple textboxes

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptc++asp-nettutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    InvalidTypecast
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • I InvalidTypecast

      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

      P Offline
      P Offline
      PrakashBhaskar
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups