Home Ask Login Register

Developers Planet

Your answer is one click away!

Android Dvlpr February 2016

How to use Sweet Alert to replace standard confirm dialog?

I want replace standart confirm dialog. My javascript function is in the MasterPage.

function checkDelete() {
    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"); 

I want call checkDelete function in the content page.How i use sweet alert in gridview templatefield button?

<asp:TemplateField ItemStyle-Width="60" HeaderText="Delete">     
    <asp:LinkButton ID="lbDelete" Runat="server" OnClientClick=" return confirm('Are you sure?');" CommandName="Delete">Delete</asp:LinkButton>     

Please help.


Rajesh February 2016

Since the javascript is available in the master page, it is equally available in the current page (if that uses the same master). Change the OnClientClick event like below and that should work.

<asp:LinkButton ID="lbDelete" Runat="server" OnClientClick="checkDelete();" CommandName="Delete">Delete</asp:LinkButton>


This is what I did to simulate your project.

  • Created a new web application project
  • Added sweet alert script, css files in the Scripts folder
  • Added reference like HTML before </head>

<link rel="stylesheet" href="Scripts/sweetalert.css"> <script src="Scripts/sweetalert.min.js"></script>

  • Added the javascript function same as what you given in the master file before </body>
  • In the default.aspx code added the below lines

<asp:LinkButton ID="lbDelete" Runat="server" OnClientClick="checkDelete();return false;" CommandName="Delete">Delete</asp:LinkButton>

This shows the sweet alert properly.

enter image description here

Post Status

Asked in February 2016
Viewed 3,694 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life