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. how to show result by pressing Enter Key in a textbox

how to show result by pressing Enter Key in a textbox

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorial
3 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    shashank veerkar
    wrote on last edited by
    #1

    Hi.. i hav a problem in asp.net,i hav a search.aspx page which hav a textbox for keywords and a dropdownList for selection of category..and a Button for doing search..when i enter keyword in textbox and select category after then pressing Enter i dont get result..i hav to explicitly click on search Button to show result..so please tell me how to show result by pressing Enter as well aas by clicking on Button..

    S 1 Reply Last reply
    0
    • S shashank veerkar

      Hi.. i hav a problem in asp.net,i hav a search.aspx page which hav a textbox for keywords and a dropdownList for selection of category..and a Button for doing search..when i enter keyword in textbox and select category after then pressing Enter i dont get result..i hav to explicitly click on search Button to show result..so please tell me how to show result by pressing Enter as well aas by clicking on Button..

      S Offline
      S Offline
      sstocker
      wrote on last edited by
      #2

      Here's an easy way to do it: //Allow hitting enter in textbox to submit form Page.RegisterHiddenField("__EVENTTARGET", "YOUR BUTTON NAME"); I hope that helps. Scott STocker

      O 1 Reply Last reply
      0
      • S sstocker

        Here's an easy way to do it: //Allow hitting enter in textbox to submit form Page.RegisterHiddenField("__EVENTTARGET", "YOUR BUTTON NAME"); I hope that helps. Scott STocker

        O Offline
        O Offline
        onlytech
        wrote on last edited by
        #3

        If you have only one button in your form, then that button is automatically assumed as default (submit type). So no need for tweaking around with EVENTTARGET hiddenfield. If you have more than one buttons, then Stockers' advice works fine for overriding the default behaviour. However I feel your problem here is not the texbox but the combobox. Hitting Enter key from textbox will work with above two methods. But hitting Enter when focus is on combobox, does not trigger the button. Try using some javascript for this purpose: First insert a dummy LinkButton in your form (this will include the hooker function __doPostBack into you HTML code). You can keep the text property of Link button as nothing. Thus the link button will not be visible on the page. Now add this script to your section. function processKeyEvent(){ if(window.event.keyCode==13) __doPostBack('Button2',''); } Note that in the abv snippet, you are programatically calling the postback feature of ASP.NET __doPostBack('Button2',''); tells the browser to postback the page assuming that Button2 was clicked. Finally, in the onkeypress event of tag, add this: onkeypress="return processKeyEvent();" hth -geo Nothing is impossible!

        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