admin管理员组文章数量:1401794
I am trying to use the sweet alert to use as a pop-up message in my ASP.NET C# application. But I think I am doing wrong because, If I click the button or Link button, nothing really happens. it's just like an element without an event.
So here is the code.
JAVASCRIPT
<script src=".min.js"></script>
<script type="text/javascript">
function Confirm(ctl, event) {
event.preventDefault();
swal({
title: "Confirm Logout?",
text: "Do you really want to log this Account out?",
type: "warning",
showCancelButton: true,
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
return true;
} else {
return false;
}
});
}
</script>
ASPX
<li class="nav-item">
<asp:LinkButton ID="btnLogout" CssClass="nav-link" runat="server" OnClick="btnLogout_Click" OnClientClick="return Confirm(this,event)"><i class="icon ion-android-exit"></i></asp:LinkButton></li>
C#
protected void btnLogout_Click(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("login.aspx");
}
I am trying to use the sweet alert to use as a pop-up message in my ASP.NET C# application. But I think I am doing wrong because, If I click the button or Link button, nothing really happens. it's just like an element without an event.
So here is the code.
JAVASCRIPT
<script src="https://unpkg./sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">
function Confirm(ctl, event) {
event.preventDefault();
swal({
title: "Confirm Logout?",
text: "Do you really want to log this Account out?",
type: "warning",
showCancelButton: true,
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
return true;
} else {
return false;
}
});
}
</script>
ASPX
<li class="nav-item">
<asp:LinkButton ID="btnLogout" CssClass="nav-link" runat="server" OnClick="btnLogout_Click" OnClientClick="return Confirm(this,event)"><i class="icon ion-android-exit"></i></asp:LinkButton></li>
C#
protected void btnLogout_Click(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("login.aspx");
}
Share
Improve this question
edited Apr 11, 2019 at 7:24
Stephan Bauer
9,2375 gold badges38 silver badges59 bronze badges
asked Apr 11, 2019 at 6:05
Boooo BoooooBoooo Booooo
551 gold badge2 silver badges11 bronze badges
2
- 2 Sweet alert work asynchronously, so your confirm function will always returns false as written, But why sweet alert itself is not displayed, I'm not sure, Is there any error in the browser console? – Mat J Commented Apr 11, 2019 at 6:18
- 1 @MatJ , It does not have an error sir. but you are right. the message is not shown. – Boooo Booooo Commented Apr 11, 2019 at 6:20
1 Answer
Reset to default 3OnClientClick waits bool result to invoke server event but Confirm methods return nothing. ( function (isConfirm)
returns async.)
You could call server event on function (isConfirm)
manually like
<script type="text/javascript">
function Confirm(ctl, event) {
event.preventDefault();
swal({
title: "Confirm Logout?",
text: "Do you really want to log this Account out?",
type: "warning",
showCancelButton: true,
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
_doPostBack('btnLogout', 'OnClick');
}
});
return false;
}
</script>
本文标签: javascriptHow to use Sweet Alert in ASPNET CStack Overflow
版权声明:本文标题:javascript - How to use Sweet Alert in ASP.NET C# - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744262599a2597792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论