473,738 Members | 7,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ENTER key falls through to unwanted handlers in Web App

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
Nov 17 '05 #1
2 1501
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 Dickow" wrote:
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

Nov 17 '05 #2
Robert Dickow wrote:
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
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1821
by: Scott | last post by:
I'm using C# to build an application. 1) I have two windows forms, A and B. 2) A uses a DataSet read from SQL server. 3) The user presses a button on A to open B. 4) B is passed a pointer to the DataSet. 5) While in B, tables in the Dataset are bound to combo box controls. 6) While in B, I add handlers to capture the SelectedIndexChanged event
0
2333
by: styler | last post by:
I am having difficulty with the page located here: http://tinyurl.com/2zwa9 I am creating a number of image sets (some left-, some right-aligned; an example of the right-aligned is shown the first figure below) in which the text accompanying the image sets flows down around them. The image sets have a single image on top and two immediately below. To create the effect, I contain the image on top in a DIV and float it, and the bottom...
3
6927
by: Simon Wigzell | last post by:
How can I interrupt the enter key so it won't trigger unwanted events on my web page? I have tried this: var defaultEventHandler = obj.getEvent("onkeydown"); var myEventHandler = function(event){ if(event.keyCode==13){ alert(obj.getProperty("selection/index")); } else{
4
19053
by: Empire City | last post by:
My windows form has some text boxes and a two buttons, Button1 and Button2. The TAB key goes from field to field. When the user presses the RETURN key I want the focus to be moved to Button1. Is there an easy way to do this or would I have to check for all keypresses in an event somewhere and manually set the focus on Button1 if the RETURN key was hit. Is so, which event would that be?
5
3133
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's click event will fire and the page will submit. I have a series of pages with Previous and Next navigational Btns. The Previous button is the first button, so when the user hits enter, the previous page is served up. Enter should result in...
15
4050
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
3
1549
by: mk | last post by:
Hi I'v got the following javascript (part of it) that works with the event onmouseup: // Attach event handlers to all images within container LICollection=document.getElementById("MDME").getElementsByTagName("LI"); if (LICollection!=null) { for (l=0; l<LICollection.length; l++) {LICollection.item(l).onmouseup=onMouseUpHandler;}
7
3169
by: Marc | last post by:
Hi, I want my user to be able to rename a button control by selcting rename from a menu. This then opens a text box in which to enter the new name in. I want the button control to inherit the name when the enter key is
18
4607
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same function, or one calls the other. Isn't there an event for 'ListBox selection selected' that is automatically called by ALL the standard GUI ways of doing it? C'mon, this is C#, we aren't supposed to be programming the GUI. There has to be such...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.