maztt
maztt

Reputation: 12294

ASP.NET MVC button multiple clicks

ok i have a form on which i have some validation through dataannotation which is client side as well as server side validation like some field already exists. i have no javascript validations on the page. now my problem is that what should i do if the user presses the save button multiple times (he keeps pressing the button for 15 times,in my case the page stays there with field already exist message at the top ) . what do u guys do for that?

what i have done (this works fine in firefox but not in ie) it disable the button no matter what just after click in ie

  $(document).ready(function () {
     $("#btn").submit(function () {
         $('#btn').attr('disabled', 'disabled');
     });
 });

Upvotes: 2

Views: 931

Answers (2)

Christian13467
Christian13467

Reputation: 5604

Put an overlay above the whole page. The overlay prevents the user from clicking twice and gives some feedback. The blockUI plugin does this very well.

EDIT:

$(document).ready(function () {
 $("#btn").click(function () {
     $('#btn').attr('disabled', 'true'); // Disable the button if you like
     $.blockUI(); // Blocking the page with a standard message.
 });
});

Upvotes: 2

Dave
Dave

Reputation: 2562

try using .live or you could hide the button after it is pressed.

$(document).ready(function () {
     $("#btn").live("click", function () {
         $('#btn').attr('disabled', 'disabled');
//or
         $('#btn').hide();
     });
 });

Upvotes: 0

Related Questions