Bootbox confirm: return client result in order to do postback to rowCommand

半城伤御伤魂 提交于 2019-12-03 08:56:55

I finally come up with this solution;

function confirmDelete(sender) {
    if ($(sender).attr("confirmed") == "true") {return true;}

    bootbox.confirm("Are you sure you want to delete?", function (confirmed) {
        if (confirmed) {
            $(sender).attr("confirmed", confirmed).trigger("click");
        }
    });

return false;
}

And changing button's OnClientClick;

OnClientClick="return confirmDelete(this);"
dannyzar

I've tried Fatih Bilginer solution, but it requires another click to do postback, so I changed .trigger("click") for sender.click();

EDIT

function confirmDelete(sender) {
    if ($(sender).attr("confirmed") == "true") {return true;}

    bootbox.confirm("Are you sure you want to delete?", function (confirmed) {
        if (confirmed) {
            $(sender).attr('confirmed', confirmed);
            sender.click();
        }
    });

return false;
}
Mohammed Khalid

I've doing a some change in dannyzar code, I used callback: to call function

and I've added some design to bootbox modal

function confirmDelete(sender) {
          if ($(sender).attr("confirmed") == "true") { return true; }

          bootbox.confirm({
          message: "Are you sure you want to delete?",
          buttons: {
              confirm: {
                  label: 'Yes',
                  className: 'btn btn-success'
              },
              cancel: {
                  label: 'No',
                  className: 'btn btn-danger'
              }
          }
          ,callback: function (confirmed) {
              if (confirmed) {
                  $(sender).attr('confirmed', confirmed);
                  sender.click();
              }
          }});

          return false;
      }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!