Is there posisble to prevent user from clicking twice in input tag button type submit? I have tried ondblclick="javascript:void(0)" But its not working
Mine is in a Html.BeginForm not a form element tag
Grateful for all the help!
Is there posisble to prevent user from clicking twice in input tag button type submit? I have tried ondblclick="javascript:void(0)" But its not working
Mine is in a Html.BeginForm not a form element tag
Grateful for all the help!
You can try one click event, it will disable second click event
$( "#XXXXX" ).one( "click", function() {
alert( "This will click only once." );
});
Put something like this to your JavaScript Code:
var tryNumber = 0;
$('input[type=submit]').click(function (event) {
var self = $(this);
if (self.closest('form').valid()) {
if (tryNumber > 0) {
tryNumber++;
// if you want an alert:
// alert('Your form has been already submited. wait please');
return false;
}
else {
tryNumber++;
}
};
});
Create a Custom ActionFilter that will keep track of the Request and add a delay value. A good explanation is on this blog. Of course this need some effort, but would finally need only one Custom Attribute on your Request function.
Personally i would say this is not the right way to look at the problem.
You can't prevent your Page from every unwanted User Interaction. Most of the time the user is doing something completed different as expected.
Instead i would make my POST Request stable and overthink my logic to make sure no Data gets corrupted.
There are some Design Patterns like the Post/Redirect/Get Pattern for this.