我想更换标准确认对话框。 我的javascript函数在MasterPage中。
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");
});
}
我想在内容页面中调用checkDelete函数。如何在gridview templatefield按钮中使用甜蜜警报?
<asp:TemplateField ItemStyle-Width="60" HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbDelete" Runat="server" OnClientClick=" return confirm('Are you sure?');" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
请帮忙。
答案 0 :(得分:1)
由于javascript在母版页中可用,因此它在当前页面中同样可用(如果它使用相同的母版)。像下面一样更改OnClientClick事件,这应该有效。
<asp:LinkButton ID="lbDelete" Runat="server" OnClientClick="checkDelete();" CommandName="Delete">Delete</asp:LinkButton>
<强>更新强>
这就是我模拟你的项目所做的。
</head>
<link rel="stylesheet" href="Scripts/sweetalert.css">
<script src="Scripts/sweetalert.min.js"></script>
</body>
<asp:LinkButton ID="lbDelete" Runat="server" OnClientClick="checkDelete();return false;" CommandName="Delete">Delete</asp:LinkButton>
这显示了正确的甜蜜警报。