validation message sweet alert display more than once when record exist before and click on submit button multi time ?

Ahmed Salah Abed Elaziz 390 Reputation points
2023-11-13T11:25:54.3866667+00:00

I work on asp.net mvc Application Ajax Request Calling I face Issue message sweet alert display more than once if i click button submit more than once

if i press same button submit again for same request it will display (message Employee Exist Before) two time

if i press same button submit button again for same request it will display message validation (message Employee Exist Before) 3 time

correct or expected behavior

when click submit button and employee exist before then show message validation (message Employee Exist Before) one time only .

why that happen and how to prevent display same message multi time

what I try as below :

<form id="ResignationApp" style="padding-top: 50px; border: 2px solid black;padding-left:20px;margin-top:30px;">
 <input id="btnsubmit" type="submit" style="background-color: #05014a; color: #fff; height: 30px; width: 150px" />
</form>

$("#ResignationApp").submit(function (e) {

            e.preventDefault();

            var formData = $(this).serialize();
            console.log("data is" + formData)
            $.ajax({
                type: "POST",
                dataType: 'json',
                url: '@Url.Action("RequesterIndex", "Resignation")',
                data: formData,
                success: function (response) {
                    for (let item of response) {
                        if (item.Key === "success") {
                            success = item.Value;
                        }

                        if (item.Key === "message") {
                            message = item.Value;
                        }
                    }
                    if (success) {

                        Swal.fire({
                            icon: 'success',
                            title: 'Submition Request',
                            text: message
                        }).then((result) => {
                            if (result.isConfirmed) {
                                var url = '@Url.Action("IndexResignation", "Home")' + '?filenumber=' + empidval;
                                window.open(url, '_self');

                                }
                            });

                    } else {
                            Swal.fire({
                                icon: 'error',
                                title: 'Resignation Submission Form',
                                text: 'Employee Exist Before'
                            });
                            return false;

                    }

                },
                error: function (error) {
                     var url = '@Url.Action("UnauthorizedUser", "Home")' + '?filenumber=' + empidval;
                     window.open(url, '_self');

                }
            });
    });

  public JsonResult RequesterIndex(ResignationRequester resignationRequester)
  {
      dynamic responseData = new ExpandoObject();
      responseData.success = false;
      responseData.message = "";

      var filenumber = resignationRequester.EmpID;
      if (Session[SessionKeys.UserCode] != null)
      {
          JDEUtility jde = new JDEUtility();


          if (ModelState.IsValid)
          {






              int checkEmployeeNoExist = jde.CheckEmployeeExistOrNot(resignationRequester.EmpID);
              if (checkEmployeeNoExist >= 1)
              {
                  responseData.success = false;
                  responseData.message = "Employee Exist Before";
                  return Json(responseData);

              }


              try
              {
                  Workforce.InsertToReignation(resignationRequester, JoinedDate, (string)Session[SessionKeys.Username], (DateTime)Session[SessionKeys.LastWorkingDate], noticeperiod, (int)Session[SessionKeys.UserCode]);
              }
              catch (Exception ex)
              {
                  responseData.success = false;
                  responseData.message = "Create Not Done Correctly";
                  return Json(responseData);
              }

              if (string.IsNullOrEmpty(ViewBag.errorMsg))
              {
                  responseData.success = true;
                  responseData.message = "Resignation Submission form Created successfully";

                  return Json(responseData);
              }



          }
          else
          {
              responseData.success = false;
              var errors = ModelState.Select(x => x.Value.Errors)
                                      .Where(y => y.Count > 0)
                                      .ToList();
              responseData.message = "Some Required Fields Not Added";
              return Json(responseData);

          }
      }
      else
      {
          responseData.success = false;
          responseData.message = "No Data For This File No";
          return Json(responseData);
      }
      return Json(responseData);

  }
Developer technologies ASP.NET Other
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-11-13T22:32:43.4233333+00:00

    its your 3rd party library. on your submit, you do not have code to close any open alerts. you require the user to manually dismiss each one.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.