I have a problem which I have worked around for some time. I would appreciate
any comments on the following statements.
When the enter key is pressed it causes a postback. After postback code has
been executed, any event driven code is executed. The most common event is
caused by a mouse click of a button. After the enter key has been pressed,
ASP seems to recognize any event and executes the associated code -
regardless of lack of mouse click or the intentions of the user or system
designer.
The most common button causes the entered detail to be validated and saved -
so an accidental Enter key press causes a few messages about required detail
missing. Most people have experienced this - we are left a bit puzzled
because we are still entering detail, but continue doing so.
The situation is made much more difficult if there is more than one button
on the form. The enter key could cause a rediretion or any number of
unexpected actions.
It may be that only one event is recognized - so if the "Save" button is
placed logically first on the firm, its event will be the only one that is
triggered when the enter key is pressed.
It seems to me to be a deficiency in ASP. I tried to overcome the problem by
using HTML buttons and JavaScript events that set flags. Java script will not
recognize a press of the enter key as an event associated with a click of a
button. The difficulty is that the HTML buttons still have to cause a
postback, requiring the Javascript command __dopostback. It worked perfectly
on two of my three forms. I still do not understand why it would not work on
the third form. I appreciate that it has to be associated with a control
which is capable of causing postback, and believe me I tried everything to
get it to work.
So my users have to wake up to themselves. This is the WWW. If they use the
enter key the detail on my form is going to be processed, and if they get
confusing messages or accidently shunt themselves off into cyberspace, that
is not my problem.