0

my code:c#

@using (Ajax.BeginForm("tt", null, opt, new { @class = "form-horizontal", @id = "AddForm" }))
{
....
<input id="submit" type="submit" class="btn btn-primary" value="Add">
}

AjaxOptions:

AjaxOptions opt = new AjaxOptions
        {
            InsertionMode = InsertionMode.ReplaceWith,
            HttpMethod = "POST",
            UpdateTargetId = "Add-Student",
            OnBegin = "OnBegin",
            OnSuccess = "ModelHideFormSubmit"
        };

script: it works in first submit, but after first submit and success massage appeared , then want to submit again the code not working any more!! why??

function OnBegin() {
            $("#AddForm :submit").prop("disabled", true);
            $("input[type='submit']", "#AddForm").val("saving...");
        }
  • 1
    possible duplicate of https://stackoverflow.com/questions/926816/how-to-prevent-form-from-submitting-multiple-times-from-client-side – Former contributor Oct 22 '19 at 07:12
  • Is your problem is that the second click doesn't cause the request? You disable a button after the first click (in OnBegin), you need to enable it back in OnSuccess function, otherwise the second time you will click the "disabled" button. Try to add $("#AddForm :submit").prop("disabled", false); into OnSuccess function. – Anna Miroshnichenko Oct 22 '19 at 07:12
  • no that not my problem, the button enabled after submit, my problem is when i want to submit again (for example: add another student) the script does not prevent multiple clicks any more, Conclusion: the code works in first time but does not work in second time ... see what i mean?? – Hamza Abu Yazan Oct 22 '19 at 07:28

1 Answers1

0

You can have a variable called isLoading. And just return false if is Loading is true and when Ajax will be finished set isLoading to false.

Arayik
  • 114
  • 2
  • 10