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. Problem with ASP.NET Postback and Mac Enter/Return key

Problem with ASP.NET Postback and Mac Enter/Return key

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascriptasp-netsysadmin
2 Posts 1 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.
  • P Offline
    P Offline
    Paul Ingles
    wrote on last edited by
    #1

    I don't know whether this a JavaScript or ASP.NET issue, so I've posted here and in the Web Development forum, hope nobody minds. I'm trying to wire up support for both Enter and Return keys on Macs to postback an ASP.NET form when they keys are pressed within a text box. At the moment, this is done through simulating a click on an ASP.NET button server control. This JavaScript function is called during the text box's onKeyPress event and looks as follows (with e being the event passed in):

    function checkEnter(e, buttonId)
    {
    var characterCode;

    if(e && e.which) {
    	characterCode = e.which; //character code is contained in NN4's which property
    } else {
    	characterCode = e.keyCode;
    }
    
    if(characterCode == 13 || characterCode == 3) {
    	return clickButton(e, buttonId);
    } else {
    	return true;
    }
    

    }

    The weird thing is, this works fine on PC keyboards (where it seems both the enter and return keys use the same key code), but on Macs only pressing return causes the form data to be posted back, pressing enter just causes the page to postback but without any data. Thinking about it, is this actually a limitation of the Mac itself, is this kind of behaviour normal? Thanks as always, -- Paul "Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office." - David Brent, from "The Office" MS Messenger: paul@oobaloo.co.uk Download my PGP public key

    P 1 Reply Last reply
    0
    • P Paul Ingles

      I don't know whether this a JavaScript or ASP.NET issue, so I've posted here and in the Web Development forum, hope nobody minds. I'm trying to wire up support for both Enter and Return keys on Macs to postback an ASP.NET form when they keys are pressed within a text box. At the moment, this is done through simulating a click on an ASP.NET button server control. This JavaScript function is called during the text box's onKeyPress event and looks as follows (with e being the event passed in):

      function checkEnter(e, buttonId)
      {
      var characterCode;

      if(e && e.which) {
      	characterCode = e.which; //character code is contained in NN4's which property
      } else {
      	characterCode = e.keyCode;
      }
      
      if(characterCode == 13 || characterCode == 3) {
      	return clickButton(e, buttonId);
      } else {
      	return true;
      }
      

      }

      The weird thing is, this works fine on PC keyboards (where it seems both the enter and return keys use the same key code), but on Macs only pressing return causes the form data to be posted back, pressing enter just causes the page to postback but without any data. Thinking about it, is this actually a limitation of the Mac itself, is this kind of behaviour normal? Thanks as always, -- Paul "Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office." - David Brent, from "The Office" MS Messenger: paul@oobaloo.co.uk Download my PGP public key

      P Offline
      P Offline
      Paul Ingles
      wrote on last edited by
      #2

      http://www.codeproject.com/script/comments/forums.asp?msg=981080&forumid=1640#xx981080xx[^] -- Paul "Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office." - David Brent, from "The Office" MS Messenger: paul@oobaloo.co.uk Download my PGP public key

      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