ENTER key falls through to unwanted handlers in Web App

  • Thread starter Thread starter Robert Dickow
  • Start date Start date
R

Robert Dickow

I have some ASP.NET Web App pages on which there are web forms with
textboxes and buttons for 'Cancel' and 'Submit' and such. All works great.
However, it a user uses the ENTER key in either of two textboxes, the
postback 'falls through' to one of the 'Cancel' button handlers, and exits
the application. Oddly, I can't use anything in the Cancel routine to check
whether the ENTER key was hit, since the sender object is always the Cancel
key itself. This behavior is unwanted, and I can't figure out how to trap
the ENTER hey strokes either on the client or server side.

On some pages I have been able to get the ENTER key to fall through to a
Submit button, which makes more sense, but I still would like to be able to
process the postback depending on the ENTER key usage or not.

What approach should I be using?

Bob
 
Bob,

In the html view of the aspx page, make sure the Submit button appears
before the Cancel button. In that way, the Enter will go to the Submit button.
 
Robert said:
I have some ASP.NET Web App pages on which there are web forms with
textboxes and buttons for 'Cancel' and 'Submit' and such. All works
great. However, it a user uses the ENTER key in either of two
textboxes, the postback 'falls through' to one of the 'Cancel' button
handlers, and exits the application. Oddly, I can't use anything in
the Cancel routine to check whether the ENTER key was hit, since the
sender object is always the Cancel key itself. This behavior is
unwanted, and I can't figure out how to trap the ENTER hey strokes
either on the client or server side.

On some pages I have been able to get the ENTER key to fall through
to a Submit button, which makes more sense, but I still would like to
be able to process the postback depending on the ENTER key usage or
not.

What approach should I be using?

Bob

Some background info:
When you hit the enter-key in the browser, that browser simulates a click
on the "default button". The browser then sends a request to the server as if that
button was clicked.
The server then has no way to know *how* that button was clicked. Asp.Net
just registers a "click" on your button.

See www.MetaBuilders.com, look for DefaultButtons. That might help.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top