Workaround: Hitting enter to submit a form in Internet Explorer does not fire an ASP.NET Button Click / Command event

There’s a funny bug in Internet Explorer that causes it to not send FirstButtonName=FirstButtonValue as a form value when there is only 1 input type=’text’ on the page. This results in the ASP.NET Button controls not firing their Click or Command events.

Now I’ve spotted a few workarounds to this problem before, but they all involve javascript. Not very elegant, and doesn’t help those with no script.

The work around I have come up with is to add a hidden text field just after the

tag. If there are no text fields on the form, then the user cannot hit enter to submit the form and if there is, then there is technically now 2 – meaning the bug won’t occur:



A few notes:

  • The ‘if IE’ ensures it only gets picked up by Internet Explorer to begin with
  • The disabled/size attributes are for browsers with no CSS so that at least its as small as possible and the user cannot focus the cursor into it.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Workaround: Hitting enter to submit a form in Internet Explorer does not fire an ASP.NET Button Click / Command event

  1. Uzi says:

    Thanks a lot! I thought I’d go mad when I couldn’t figure out what’s wrong with my page, but now I understand that it is thanks to the guys in Redmond. How did you ever find out what’s causing it?//Vince

  2. Stephen O says:

    Holy crap! Who would ever have thought of that. I was going crazy until I found your post. My situation was the very common one of having a single text search box and a “Go” button….Get a grip Microsoft! People don’t want to hit the button, they want to hit the Enter key!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s