Bootbox确认:返回客户端结果以便回发到rowCommand

nin*_*bit 3 javascript c# asp.net gridview bootbox

在bootbox之前,我在gridview的aspx文件中做了这个;

<asp:Button ID="btnDelete" CssClass="btn btn-danger" OnClientClick="if(!confirmDelete()) return false;" runat="server" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CausesValidation="false" CommandName="DeleteRow" Text="Delete"/>
Run Code Online (Sandbox Code Playgroud)

和js文件;

function confirmDelete() {
return confirm("Are you sure you want to delete the record?"); }
Run Code Online (Sandbox Code Playgroud)

并通过确认,触发gridview的RowCommand并完成删除.

有了bootbox,我真的被卡住了.我知道bootbox是异步并尝试使用'preventDefault',但它不起作用.那么如何将上面的js文件转换为bootbox版本呢?提前致谢.

nin*_*bit 5

我终于想出了这个解决方案;

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;
}
Run Code Online (Sandbox Code Playgroud)

并更改按钮的OnClientClick;

OnClientClick="return confirmDelete(this);"
Run Code Online (Sandbox Code Playgroud)


dan*_*zar 5

我已经尝试过Fatih Bilginer解决方案,但它需要再次单击才能进行回发,所以我更改.trigger("click")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;
}
Run Code Online (Sandbox Code Playgroud)