[英]sweet alert confirm dialog in asp.net
I am able to get the alerts for isConfirm both true and false in sweet alert but unable to pass the same to btnSave to call btnSave_Click method in codebehind.我能够在甜蜜警报中获得 isConfirm 的 true 和 false 警报,但无法将其传递给 btnSave 以在代码隐藏中调用 btnSave_Click 方法。 Please help.
请帮忙。 Using latest sweetalert, downloaded from http://t4t5.github.io/sweetalert/ .
使用最新的 Sweetalert,从http://t4t5.github.io/sweetalert/下载。
<script type="text/javascript">
$('body').on('focus', ".Datetext", function () {
$(this).datepicker();
});
function Confirm(th, e) {
e.preventDefault();
swal({
title: "Are you sure?",
text: "You want to Save this project?",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, I am sure!',
cancelButtonText: "No, cancel it!",
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
//return true;
alert("true");
// $(this).trigger('click');
$("#<%= btnSave.ClientID %>").trigger('click');
// e.currentTarget.submit();
} else {
// return false;
// alert("False");
}
});
}
</script>
html html
<div style="text-align: center;">
<asp:Button ID="btnSave" CssClass="buttons___" runat="server" Font-Size="9pt" Text="Save Project"
OnClick="btnSave_Click" OnClientClick="Confirm(this, event);"/>
<asp:Button CssClass="buttons___" runat="server" Font-Size="9pt" Text="Save as Draft" />
</div>
Please try below changes in your code请尝试在您的代码中进行以下更改
<asp:Button ID="btnSave" CssClass="buttons___" runat="server" Font-Size="9pt" Text="Save Project"
OnClick="btnSave_Click" OnClientClick="return Confirm(this, event);"/>
and in Script of sweet alert并在甜蜜警报的脚本中
function (isConfirm) {
if (isConfirm) {
return true;
// alert("true");
// $(this).trigger('click');
$("#<%= btnSave.ClientID %>").trigger('click');
// e.currentTarget.submit();
} else {
return false;
// alert("False");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.