我想知道这是否可以将甜蜜警报与asp.net linkbutton相结合。例如,我有这个按钮从gridview中删除行,我想启动甜蜜警报样式
我的代码:
<asp:LinkButton ID="LinkButton3" CssClass="btn btn-danger btn-sm" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to remove this item?');" runat="server"><span class="glyphicon glyphicon-trash"></span></asp:LinkButton>
这是一个甜蜜的警示示例:
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"); });
答案 0 :(得分:1)
我还没有找到一种方法来使用gridview rowcommand函数,所以将id值传递给SweetAlert confirm函数并通过隐藏按钮回传。
function myConfirm(msgID) {
$("#<%=hfMsgID.ClientID%>").val(msgID);
swal({
title: "Are you sure?",
text: "You will not be able to recover this message!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function () {
$("#<%=btnDeleteMsg.ClientID%>").click();
});
}
<asp:HiddenField ID="hfMsgID" runat="server" />
<asp:Button ID="btnDeleteMsg" runat="server" CssClass="hidden" />
在后面的代码中,您可以从隐藏按钮的点击事件中执行。只需访问id的隐藏字段值,然后在执行后重新加载/重新绑定。