Thursday, August 25, 2011

ASP.NET: Disable Submit Form on Enter Key

By default, ASP.NET submits a form when the enter key is pressed.  When more than one is present, the first submit button in the page is 'clicked'.  You can change the default button which is pressed when the user presses the Enter key by using the following attribute in the form

<form id="form1" runat="server" defaultbutton="btnDefaultButton" >

I used this technique in order to disable this behaviour by using a dummy button at the end of the screen and pointing the defaultbutton to this button.  The dummy button must be invisible and do nothing, so here's the code

At the top:
<form id="form1" runat="server" defaultbutton="btnDisableEnter" >

At the bottom:
<asp:Button ID="btnDisableEnter" runat="server" Text="" OnClientClick="return false;" style="display:none;"/>

It seems to do the job quite well till now.  Let me know if you have a better solution or if you found it useful


  1. Thank you, that´s just what i´ve been looking for....

  2. Thank you, it works but I have a question. I'm using a master page and I need to capture the "Enter" event. How can I capture that event in any page that use the master page?

    1. you will need to use javascript onkeydown or keypress event. Watch out for browser incompatibilities!

    2. When using a master page, the DefaultButton property can be set on a Panel instead.

  3. Good solution, but you cannot use Enter to click a button that has the focus...


  4. This Goos Solution !!!!
    But I have found something very good with JS
    Try This. Working fine !!!

  5. Packers and Movers in Delhi @
    Packers and Movers in Gurgaon @
    Packers and Movers in Noida @
    Packers and Movers in Faridabad @
    Packers and Movers in Dwarka @
    Packers and Movers in Ghaziabad @
    Packers and Movers in Marathahalli @
    Packers and Movers in Hyderabad @

  6. I must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1.. We Provide Best Packers And Movers Bangalore List for Get Free Best Quotes, Compare Charges, Save Money And Time,
    Household Shifting Services. @ Packers And Movers in Bangalore

  7. Excellent post! I must thank you for this informative read. I hope you will post again soon. Warehousing of merchandise .
    While general look the things you ought to utilize little stockpiling zone space stockpiling range compartments to program the aides. Books get to be heavier when pressed 7 or more aides in a crate.
    Packers And Movers Chennai

  8. Really impressive post. I read it whole and going to share it with my social circules. I enjoyed your article and planning to rewrite it on my own blog.
    please visit here
    Packers And Movers Bangalore

  9. I must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1...Please visit our wonderful and valuable website-
    Packers and Movers Mumbai

  10. Lovely Website, Maintain the fantastic work. Thank you so much!
    We Provide Best Packers And Movers ahmedabad List for Get Free Best Quotes, Compare Charges,
    Save Money And Time, Household Shifting Services @
    Packers and Movers Ahmedabad

  11. Local Packers and Movers Chennai list, Cheap Packers Movers Chennai Charges, Affordable, Best Household Shifting Chennai visit here : Packers and Movers Chennai charges

  12. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingAzure Online training Hyderabad

  13. Absolutely nothing is cost-free on this planet, but guarantee that you Buy facebook reviews exclusively from valid sources for good reputation on-line. buy facebook reviews ratings

  14. Very Nice Article to read. Blog articles helped me alot in many ways to find the good solution. Am very happy to comments here. Thanks for sharing this kind of wonderful article in this blog. Lovely ! Kindly Visit Us @
    CCTV Camera Supplier | MATRIX dealers in Trivandrum

  15. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels

  16. You are a crack, still working on 2019

  17. Thanks for sharing this information with us. Your content is very Informative and useful. I admire it.

    We are providing professional packers and movers services all over India an affordable price.
    Packers and movers in Ghaziabad
    Packers and Movers in Noida
    Packers and Movers in Delhi
    Packers and Movers in Gurgaon

  18. Thank you very much for keeping this information Share this.
    Jai Balaji Packers and Movers
    Contact - +91 9838276084, 9808623702
    Jai Balaji Packers and Movers offering very quality-situated administrations. Be that as it may, it has its branches in all over India. We take into account the variable needs of our clients by offering administrations like Home migration, Office movement, Packing and Unpacking, Loading and Unloading. These administrations can be profited from any alcove and corner of the nation.

  19. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. Submit Articles

  20. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.. windows azure training

  21. Spolu offers OnePlus, Mi, Vivo, Lenovo & iPhone all types od mobile mobiles repair service at your doorstep. All our phone repairs come with 6 months warranty, same day service. We'll send you a text with a link to download the app.
    You can download the mobile app here-
    Doorstep Mobile Repair Service in Noida

  22. Orel State University which is also known as Government State Educational Institution of Higher Education is identified as a prime higher education Institution in the metropolis of Orel. Orel State University was founded in 1931 as an industrial-Pedagogical Institute. In 1932 Orel Pedagogical University became Orel State University. Orel State University is unique in many aspects.
    To get Admission and more information-
    Orel State Medical University

  23. If you are planning to move or move near in the future and are worried about the fraudulent activities by such packers and movers, Don’t Worry We “ Kp Logistics, Best packers and movers in Chennai” are here to help you with how to identify and avoid such cheaters.

  24. When you are moving to a new city or within a city the important thing is to find affordable and cheapest packers and movers in pune, Based on my experience cargo balaji packers and movers pune is best at an affordable price.

  25. Get the best disposable medical product from mais india,we are manufacturer company, our manufacturer products are- Iv cannula, safety iv cannula,3way-stopcock, 3way-stopcock with extension tube, foley catheter, endotracheal tube, pressure monitoring line, etc. For more details visit our website -
    Mais India | IV Cannula | Safety IV Cannula

  26. Thank you for sharing such a really admire your post. Your post is great! . micronutrients fertilizer for plants

  27. İnstagram takipçi satın al! İnstagram takipçi sitesi ile takipçi satın al sende sosyal medyada fenomen olmaya bir adım at. Sende hemen instagram takipçi satın almak istiyorsan tıkla:

    1- takipçi satın al

    2- takipçi satın al

    3- takipçi satın al