Posted by: pureblue | April 2, 2007

IE – “Postback when Enter pressed” bug!

I’ve just fixed a strange bug I was having when comparing a web page in IE and Firefox. The page simply had a single textbox, and a button. By default, in accordance with W3C standards, both browsers will post-back to the server when the user hits <Enter> from within the textbox.

Just the behaviour I wanted, except that when the post-back occurs from IE, the button’s event handler does not get triggered on the server!! Very strange … but this article on 4guysfromrolla.com gives a great explanation.

Basically, IE does not post-back a fully serialised form if there is only one textbox on the page! The server does not know what triggered the post-back and so cannot call the correct server-side event handler. The workaround? … add another textbox to the form (but just make it hidden!).

This is true for IE6 and IE7 …

Update 5 APR 2008: An example would be nice, so this is what I used…

<asp:TextBox ID=”IEPostbackBugFix” runat=”server” style=”visibility:hidden;display:none;” />

Advertisement

Responses

  1. Great Article. Question:In ASP.NET, It’s not enough to just make the visibility=false on the dummy ASP:textbox. The misfire will still occur.

    Are you saying add an HTML textbox?

  2. It should not matter if it is an ASP.NET controlled text box or a manually added HTML one. It was a while since I researched all of this, but I found a code example, so I’ve updated the post so you can give that a go.


Leave a Reply

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

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

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

Categories

Follow

Get every new post delivered to your Inbox.