Problem with ASP.NET Postback and Mac Enter/Return key
-
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'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
Ok, turns out that this error is caused by an IE bug when a form contains a single text box. It can be solved in JavaScript, but an easier workaround is to place an additional text box on the form that is not visible. -- 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