在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"/>
和js文件;
function confirmDelete() {
return confirm("Are you sure you want to delete the record?"); }
确认后,触发 gridview 的 RowCommand 并完成删除。
有了bootbox,我真的卡住了。我知道 bootbox 是异步的并尝试使用“preventDefault”,但它没有用。那么如何将上面的js文件转成bootbox版本呢? 提前致谢。
最佳答案
我终于想到了这个解决方案;
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;
}
并更改按钮的 OnClientClick;
OnClientClick="return confirmDelete(this);"
关于javascript - Bootbox确认: return client result in order to do postback to rowCommand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30912017/