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. Web Forms and the Enter Key

Web Forms and the Enter Key

Scheduled Pinned Locked Moved ASP.NET
htmlasp-nethelptutorialquestion
3 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.
  • E Offline
    E Offline
    exhaulted
    wrote on last edited by
    #1

    Hi folks, help you can help me. I have a base web page that all my forms are inheriting from and i want to use it to control the behaviour of the enter key in the inheriting pages. Specifically, i need to ignore the enter key if it is pressed on any type of control other than a button control, either a html or asp button. I was thinking of JScript but don't know how to determine wether the object that had focus when the enter key was pressed was a button or not. Anyone able to help with this? Cheers Kev

    A 1 Reply Last reply
    0
    • E exhaulted

      Hi folks, help you can help me. I have a base web page that all my forms are inheriting from and i want to use it to control the behaviour of the enter key in the inheriting pages. Specifically, i need to ignore the enter key if it is pressed on any type of control other than a button control, either a html or asp button. I was thinking of JScript but don't know how to determine wether the object that had focus when the enter key was pressed was a button or not. Anyone able to help with this? Cheers Kev

      A Offline
      A Offline
      Albert Pascual
      wrote on last edited by
      #2

      Check this javascript works well for me function clickButton() { if (event.keyCode == 13) { if ( document.Form1.all.BT_Name != null) document.Form1.all.BT_Name.click(); return false; } } Cheers Al

      E 1 Reply Last reply
      0
      • A Albert Pascual

        Check this javascript works well for me function clickButton() { if (event.keyCode == 13) { if ( document.Form1.all.BT_Name != null) document.Form1.all.BT_Name.click(); return false; } } Cheers Al

        E Offline
        E Offline
        exhaulted
        wrote on last edited by
        #3

        I was after soemthing more generic that would work at a page level for all objects on the page, any button that has focus when enter is pressed will fire, any other control will not cause the page to be submited. One of the guys at work sent me this from a google group.

        function disableEnter(evt)
        {
        	var evt  = (evt) ? evt : ((event) ? event : null);
        	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        	
        	if ((evt.keyCode == 13) && (node.type=="text"))
        	{
        		return false;
        	}
        }
        document.onkeypress = disableEnter;
        

        It seems to work for what i want, maybe it will help anyone else who needs to do this sort of thing. Cheers Kev

        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