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. Button Click when 'Enter' key is pressed

Button Click when 'Enter' key is pressed

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
5 Posts 3 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.
  • V Offline
    V Offline
    Vsree
    wrote on last edited by
    #1

    Hi Am having a web page with many textboxes and 3 buttons(button1,button2,button3). Since there are many textboxes,the user can enter value in them with no tab order,according to his convenience. My requirement is that -- Wherever the cursor is focussing(any of the textboxes),when the user clicks 'Enter' key,it should activate the Button1's Click event. Can anyone help me how to do this? Thanks!

    V 1 Reply Last reply
    0
    • V Vsree

      Hi Am having a web page with many textboxes and 3 buttons(button1,button2,button3). Since there are many textboxes,the user can enter value in them with no tab order,according to his convenience. My requirement is that -- Wherever the cursor is focussing(any of the textboxes),when the user clicks 'Enter' key,it should activate the Button1's Click event. Can anyone help me how to do this? Thanks!

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      Trap keypress 13

      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

      V 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        Trap keypress 13

        Vasudevan Deepak Kumar Personal Homepage Tech Gossips

        V Offline
        V Offline
        Vsree
        wrote on last edited by
        #3

        Thanks Deepak I tried like this... function buttonClick() { if ((window.event.which == 13) || (window.event.keyCode == 13)) { document.getElementById('btnDisplay').click(); return true; } else return false; } And in Code behind, i tried as HtmlForm form1 = (HtmlForm)Page.FindControl("Form1"); form1.Attributes.Add("onkeydown","javascript:buttonClick()"); Is this correct ? In which event actually i need to call the Javascript? Please help me!

        B 1 Reply Last reply
        0
        • V Vsree

          Thanks Deepak I tried like this... function buttonClick() { if ((window.event.which == 13) || (window.event.keyCode == 13)) { document.getElementById('btnDisplay').click(); return true; } else return false; } And in Code behind, i tried as HtmlForm form1 = (HtmlForm)Page.FindControl("Form1"); form1.Attributes.Add("onkeydown","javascript:buttonClick()"); Is this correct ? In which event actually i need to call the Javascript? Please help me!

          B Offline
          B Offline
          blue_arc
          wrote on last edited by
          #4

          the logic is right but thw way u implemented is not right..... do one thing function buttonClick() { if ((window.event.which == 13) || (window.event.keyCode == 13)) { alert("Got U!!") return true; } else return false; } function OnPageLoad() { document.getElementById("Button").onkeydown=buttonClick; document.forms["FORM_NAME"].onkeydown=buttonClick; }

          V 1 Reply Last reply
          0
          • B blue_arc

            the logic is right but thw way u implemented is not right..... do one thing function buttonClick() { if ((window.event.which == 13) || (window.event.keyCode == 13)) { alert("Got U!!") return true; } else return false; } function OnPageLoad() { document.getElementById("Button").onkeydown=buttonClick; document.forms["FORM_NAME"].onkeydown=buttonClick; }

            V Offline
            V Offline
            Vsree
            wrote on last edited by
            #5

            Thanks friend! But there's no attribute 'removed' in tag. is it enough that i just include that attribute? Can you please help me?

            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