2015-06-18 21 views
1

在bootbox之前,我在gridview中的aspx文件中做了這個;Bootbox確認:返回客戶端結果爲了做回發到rowCommand

<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?"); } 

並且通過確認,gridview的RowCommand被觸發並且刪除完成。

隨着bootbox,我真的卡住了。我知道bootbox是asynchronus並嘗試使用'preventDefault',但它不起作用。那麼如何將上述js文件轉換爲bootbox版本? 在此先感謝。

回答

4

我終於想出了這個解決方案;

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);" 
1

我試過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; 
} 
1

我在dannyzar做了一些改變代碼,我用callback:來調用函數

我添加了一些des ign 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; 
     } 
相關問題