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

61 comments:

  1. Replies
    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
      or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

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

    ReplyDelete
  3. 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?

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

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

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

    junhyjunhy

    ReplyDelete
  5. This Goos Solution !!!!
    But I have found something very good with JS
    http://www.itorian.com/2012/07/stop-from-submission-posting-on-enter.html
    Try This. Working fine !!!

    ReplyDelete
  6. Packers and Movers in Delhi @
    https://www.egpackers.in/packers-and-movers-delhi.php
    Packers and Movers in Gurgaon @
    https://www.egpackers.in/packers-and-movers-gurgaon.php
    Packers and Movers in Noida @
    https://www.egpackers.in/packers-and-movers-noida.php
    Packers and Movers in Faridabad @
    https://www.egpackers.in/packers-and-movers-faridabad.php
    Packers and Movers in Dwarka @
    https://www.egpackers.in/packers-and-movers-dwarka-delhi.php
    Packers and Movers in Ghaziabad @
    https://www.egpackers.in/packers-and-movers-ghaziabad.php
    Packers and Movers in Marathahalli @
    https://www.egpackers.in/packers-and-movers-marathahalli-bangalore.php
    Packers and Movers in Hyderabad @
    https://www.egpackers.in/packers-and-movers-hyderabad.php

    ReplyDelete
  7. 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

    ReplyDelete
  8. There's a lot of interesting info here! I'm very grateful for the post! movers and packers hyderabad , is here to make your life simpler.
    Packers And Movers Hyderabad

    Packers And Movers begumpet-hyderabad
    P ackers And Movers banjara-hills

    ReplyDelete
  9. 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

    ReplyDelete
  10. 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

    ReplyDelete
  11. Lovely Website, Maintain the fantastic work. Thank you so much!
    Local Packers and Movers delhi list, Cheap Packers Movers delhi Charges, Affordable, Best Household Shifting delhi @
    http://packersmovers.top/delhi/

    ReplyDelete
  12. 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

    ReplyDelete
  13. 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

    ReplyDelete
  14. must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1..
    Packers And Movers Bangalore to hyderabad

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

    ReplyDelete
  16. very good post which I really enjoy reading. It is not every day that I have the possibility to see something like this.
    Packers And Movers Pune

    ReplyDelete
  17. 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 updating.more php jobs in hyderabad.

    ReplyDelete
  18. Good post and I like it very much. By the way, anybody try this increase app downloads? I do not how to use.

    ReplyDelete
  19. • 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

    ReplyDelete
  20. 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

    ReplyDelete
  21. Packers and Movers Chennai Give Safe and Reliable ***Household Shifting Services in Chennai with Reasonable ###Packers and Movers Price Quotation. We Provide Household Shifting, Office Relocation, ✔✔✔Local and Domestic Transportation Services, Affordable and Reliable Shifting Service Charges @
    Packers And Movers Chennai

    ReplyDelete
  22. 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

    ReplyDelete
  23. Manish Packers and Movers Pvt Ltd as a Services providing company can make all the difference to your Home Relocation experience. Indore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a Household Shifting, Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges, Visit :
    Manish Packers and Movers Ptv Ltd @ https://www.manishpackersmoversindore.in/
    Packers and Movers Indore @ https://www.manishpackersmoversindore.in/packers-and-movers-indore.html
    Manish Packers Indore @ https://www.manishpackersmoversindore.in/manish-packers-and-movers-indore.html
    Packers and Movers Gurgaon @ https://www.manishpackersmoversindore.in/packers-movers-gurgaon.html
    Packers and Movers Kolkata @ https://www.manishpackersmoversindore.in/packers-movers-kolkata.html
    Packers and Movers Mumbai @ https://www.manishpackersmoversindore.in/packers-movers-mumbai.html
    Packers and Movers Bhopal @ https://www.manishpackersmoversindore.in/packers-movers-bhopal.html
    Packers and Movers Nagpur @ https://www.manishpackersmoversindore.in/packers-movers-nagpur.html
    Packers and Movers Raipur @ https://www.manishpackersmoversindore.in/packers-movers-raipur.html
    Packers and Movers Ahmedabad @ https://www.manishpackersmoversindore.in/packers-movers-ahmedabad.html

    ReplyDelete
  24. 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

    ReplyDelete
  25. Packers and Movers in Delhi-We Have a core expertise of twenty years during this field we have a tendency to worth your merchandise in Transfering your merchandise from one location to a different.

    ReplyDelete
  26. You are a crack, still working on 2019

    ReplyDelete
  27. 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

    ReplyDelete
  28. Thank you very much for keeping this information Share this.
    Jai Balaji Packers and Movers
    Contact - +91 9838276084, 9808623702
    jaibalajipackersandmoversagra@gmail.com
    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.

    ReplyDelete
  29. 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

    ReplyDelete
  30. The post is very nice. I just shared on my Facebook Account.

    Checkout my site: Increase Fans on Facebook

    ReplyDelete
  31. 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

    ReplyDelete
  32. 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

    ReplyDelete
  33. 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

    ReplyDelete
  34. Orel State University is unique in many ways. It is the only classical university Orel, a member of the Association of classical Russian universities. It is the only institution in the region, which is training on a wide range of areas and specialties of higher and postgraduate education, training, re-training (more than 300).
    To Get more information and Admission-
    Orel State Medical University

    ReplyDelete
  35. Orel State University is unique in many aspects. Orel State University is the only classical university who is the member of the Association of classical universities of the Russian Federation and the only educational institution in the region which provide training on a wide range of areas and specialties of higher and postgraduate education, training, retraining.

    Orel State Medical University

    ReplyDelete
  36. Watch Asian Dramas Movies and Shows with English Subtitles - Dramacool

    ReplyDelete