find a location for property in a new city

Monday, 14 January 2013

Web forms button click event not firing in IE

There are probably many reasons why a button would not fire in an ASP.NET web forms application. Some can be fixed with deleting cookies and history, some are to do with when the event is registered. I found a new one though.

In my scenario I had a text box that was submitted with a button next to it. We didn't want to display the button though but instead wanted the form submitted with a click of the Enter button. The button was therefore wrapped in a display:none span, like this:

<input type="text" id="txtInput" onchange="btnGo_Click" runat="server"/>
<asp:Button style="display:none;" runat="server" OnClick="btnGo_Click" />
<asp:Label ID="lblOutput" runat="server" />

It turns out that this worked just fine in Chrome and Firefox but not in IE9. This was because not all browsers post data that is hidden with CSS. Security possibly? You could see this by looking at the request in Fiddler. There was no value for the button field in IE but there was for the others.

How to submit a form by clicking Enter and hiding the button

The best way I can think of is to hide the button without hiding it... How? You can push it miles of the page to hide the button with some CSS like this:

<input type="text" id="txtInput" onchange="btnGo_Click" runat="server"/>
<asp:Button style="position:absolute;left:-9999px;" runat="server" OnClick="btnGo_Click" />
<asp:Label ID="lblOutput" runat="server" />

This will put the button miles off to the left never to be seen by the user.

Follow britishdev on Twitter

10 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I love to read this type of material Good and attractive information I take from it..Thank you for posting such a good article
    happy wheels ez
    super mario bros
    pacman
    agario

    ReplyDelete
  3. I really like this kind of post here. I want to share more post about that topic. keep it up. Grass mats from groundreinforcementmesh.co.uk from http://groundreinforcementmesh.co.uk/grass-mats.html

    ReplyDelete
  4. The blog is Really informative and looks realistic. I appreciate your style and surely come back again to increase my knowledge.Mostly comments to match to eatch other.I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got Garage Flooring

    ReplyDelete
  5. I have encountered this situation and very difficult to overcome it. Thank you for giving me helpful information
    signature:
    head soccer - Big Head Soccer - head soccer - Big Head Soccer - Tiny Tanks - Tiny Planes

    ReplyDelete
  6. This blog is so nice to me. I will continue to come here again and again. Visit my link as well. Good luck
    obat aborsi
    cara menggugurkan kandungan

    ReplyDelete
  7. Companies particular with us carry all kind of shifting successfully.
    Ask definitely without any price shifting views and deal with your Moving
    price extensive variety accordingly.
    Shifting and Moving in Gurgaon
    Household Moving in Delhi
    Professional Packers and Movers in Noida

    ReplyDelete
  8. Packers and movers of India have a well qualified staff to deal
    with home items with careful attention while caring it to automobile,
    during transportation and when unloading happens, shifting alternatives etc.
    Packing and Moving in Pune
    Packer and Mover Mumbai
    Reliable Packing Services in Navi Mumbai

    ReplyDelete
  9. Packers and Movers India have exceptionally delineated vehicles which
    have bounteous and adequate recognize to keep your stock. They are staggering
    properly secured vehicles along these lines keep items from outside unsettling impact.
    Safe Packaging and Moving in Chennai
    Secure Move in Faridabad
    Get Best Movers in Ghaziabad

    ReplyDelete