我能够在甜蜜的警报中获取isConfirm的警告,无论是真还是假,但是无法将其传递给btnSave以在代码隐藏中调用btnSave_Click方法。请帮忙。使用最新的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
<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>
答案 0 :(得分:0)
请在代码中尝试以下更改
<asp:Button ID="btnSave" CssClass="buttons___" runat="server" Font-Size="9pt" Text="Save Project"
OnClick="btnSave_Click" OnClientClick="return Confirm(this, event);"/>
和甜蜜警报脚本
function (isConfirm) {
if (isConfirm) {
return true;
// alert("true");
// $(this).trigger('click');
$("#<%= btnSave.ClientID %>").trigger('click');
// e.currentTarget.submit();
} else {
return false;
// alert("False");
}
}