I have made the confirmation but have not used sweet alerts and it is working correctly
this is my code before
<asp:Button ID="btnSaveDetail" CssClass="btn btn-primary col-sm-2" runat="server" Text="Setujui" OnClick="btnSaveDetail_Click" OnClientClick = "Confirm()" />
<script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Apakah Kamu Yakin Menyimpan Data Ini?")) {
confirm_value.value = "Ya";
} else {
confirm_value.value = "Tidak";
}
document.forms[0].appendChild(confirm_value);
}
and there is condition when i klik OK in aspx.cs like this
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Ya")
{
if (check == 1)
{
DateTime date = DateTime.Now;
string date_str = date.ToString("yyyy-MM-dd");
lib.CallProcedure("[iu_update_Konfirmpeminjaman]", new string[] { lblID.Text, "5", Session["creaby"].ToString(), date_str, Session["creaby"].ToString(), date_str });
loadData();
}
else {
DateTime date = DateTime.Now;
string date_str = date.ToString("yyyy-MM-dd");
lib.CallProcedure("[iu_update_Konfirmpeminjaman]", new string[] { lblID.Text, "3", Session["creaby"].ToString(), date_str, Session["creaby"].ToString(), date_str });
loadData();
}
}
But i want to make it with sweet alerts, i tried but still not works, i changed my code like this, can u guys help me how to make it works?
<asp:Button ID="btnSaveDetail" CssClass="btn btn-primary col-sm-2" runat="server" Text="Setujui" OnClick="btnSaveDetail_Click" OnClientClick="return setujuialert(this, event);" />
<script type="text/javascript">
function setujuialert(ctl, event) {
var defaultAction = $(ctl).prop("href");
event.preventDefault();
swal({
title: "Penyetujuan",
text: "Apakah Anda Yakin Ingin Menyetujui Peminjaman ini?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Ya",
cancelButtonText: "Tidak",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (isConfirm) {
swal({ title: "Berhasil!", text: "Peminjaman Berhasil Disetujui.", type: "success", confirmButtonText: "OK!", closeOnConfirm: false },
function () {
confirm_value.value = "Ya";
return true;
});
} else {
swal("Batal", "Peminjaman Batal Disetujui", "error");
return false;
}
});
}
Aucun commentaire:
Enregistrer un commentaire