Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Before bootbox, I did this on aspx file in gridview;

<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"/>

and on js file;

function confirmDelete() {
return confirm("Are you sure you want to delete the record?"); }

And with confirmation, the gridview's RowCommand is triggered and the deletion is done.

With bootbox, I am realy stuck. I know bootbox is asynchronus and try to use 'preventDefault', but it didn't work. So how can I convert the above js file to bootbox version? Thanks in advance.

like image 845
ninbit Avatar asked Dec 10 '22 22:12

ninbit


1 Answers

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);"
like image 92
ninbit Avatar answered Jan 18 '23 23:01

ninbit