Reputation: 97
I want replace standart confirm dialog. My javascript function is here
function checkDelete() {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning", showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes Delete it!",
closeOnConfirm: false
},
function () {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
}
How i use sweet alert confirm function in gridview templatefield button?
<asp:TemplateField ItemStyle-Width="60" HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbDeleteUser" Runat="server" OnClientClick="checkDelete();" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Standart confirm function is here
<asp:TemplateField ItemStyle-Width="60" HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbDeleteUser" Runat="server" OnClientClick=" return confirm('Are you sure?');" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Standart confirm function is runnning. But sweet alert confirm function is not running. Please help
This is standart confirm
Plase help.
Upvotes: 2
Views: 6602
Reputation: 51
In case someone needs help in the future here is the piece of code i have used to implement this.
swal({
title: '',
text: "Are you sure you want to delete selected record(s) ?",
type: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText: '<i class="fa fa-times"></i> @Resources.No',
confirmButtonText: '<i class="fa fa-check"></i> @Resources.Yes'
}).then(function () {
// loop on selected rows and remove them using jquery datatable method.
// display sweet alert
swal(
{
title: "",
text: "Record Deleted",
type: "success",
allowOutsideClick: "true"
});
})
Happy coding!
Upvotes: 0
Reputation: 1
Don't know how is your issue going so far, but here is my ugly solution.
function confirmBeforePostback(obj) {
var res = $(obj).attr('onclick').split(';');
if (res.length > 1) {
swal({
title: "Are you sure?",
text: "The will delete your record, are you sure?",
showCancelButton: true,
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
eval(res[1]);
}
});
}
return false;
}
And in the asp.net, add code to the onclick attribute like below example.
Code behind:
((Button)e.Row.Cells[5].Controls[2]).Attributes["onclick"] = "if(!confirmBeforePostback(this)) return false;";
or ASPX:
<ItemTemplate>
<asp:LinkButton ID="lbDeleteUser" Runat="server" OnClientClick="confirmBeforePostback(this);" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
Upvotes: 0
Reputation: 518
Use this code, It will help you
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file.",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#F44336",
confirmButtonText: "Yes, Sure !",
closeOnConfirm: true
}, function () {
swal({
title: "Message",
text: 'Imaginary file deleted.',
type: "success"
}); });
Upvotes: 2