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