Display jQuery Sweetalert Confirmation Box before Delete on LinkButton Click in ASP.Net

Last Reply 8 days ago By dharmendr

Posted 9 days ago

Hello,

I have this popup JavaScript i want to call it on LinkButton ClientClick

Please advice

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
    function confirm() {
        swal({
            title: "Are you sure?",
            text: "Once deleted, you will not be able to recover this imaginary file!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        })
        .then((willDelete) => {
            if (willDelete) {
                swal("Poof! Your imaginary file has been deleted!", {
                    icon: "success",
                });
            } else {
                swal("Your imaginary file is safe!");
            }
        });

        return false;
    }
</script>
<asp:LinkButton ID="LinkButton5" runat="server" OnClientClick="retun confirm();">LinkButton</asp:LinkButton>

 

You are viewing reply posted by: dharmendr 8 days ago.
Posted 8 days ago

Hi nauna,

Refer below sample code.

HTML

<asp:LinkButton ID="LinkButton5" runat="server" OnClientClick="return confirm()">Delete</asp:LinkButton>
<script type="text/javascript" src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">
    function confirm() {
        swal({
            title: "Are you sure?",
            text: "Once deleted, you will not be able to recover this imaginary file!",
            icon: "warning",
            buttons: true,
            dangerMode: true
        }).then(function (isConfirm) {
            if (isConfirm) {
                swal("Poof! Your imaginary file has been deleted!", {
                    icon: "success"
                });
            } else {
                swal("Your imaginary file is safe!");
            }
        });

        return false;
    } 
</script>

Screenshot