0

I want replace standart confirm dialog. My javascript function is in the 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"); 
  });
}

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">     
  <ItemTemplate>        
    <asp:LinkButton ID="lbDelete" Runat="server" OnClientClick=" return confirm('Are you sure?');" CommandName="Delete">Delete</asp:LinkButton>     
  </ItemTemplate>
</asp:TemplateField>
</Columns>

Please help.

admix
  • 1,752
  • 3
  • 22
  • 27
Android Dvlpr
  • 97
  • 3
  • 13

1 Answers1

1

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>

Update

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

Rajesh
  • 934
  • 12
  • 23
  • I changed OnClientClick="checkDelete();". But not running confirm button – Android Dvlpr Feb 09 '16 at 12:03
  • Can you check console to see any errors, possibly there could be reference errors. – Rajesh Feb 10 '16 at 04:56
  • Also check these threads [link] (http://stackoverflow.com/questions/32164151/sweet-alert-continue-submitting-form-on-confirm?rq=1) and [another](http://stackoverflow.com/questions/33414259/response-from-sweet-alert-confirm-dialog?rq=1) which are very similar – Rajesh Feb 10 '16 at 05:47
  • I checked. But not working. I don't have an error. Please help – Android Dvlpr Feb 10 '16 at 10:37