TechGuy
TechGuy

Reputation: 4570

Delete Confirmation in Client Side

In my Ajax function there's a table & inside it there's a Delete button.It's working But i wanted to do When someone Click that delete button then it needs to ask the Confirmation dialogue.I know it's easily we can do it with OnClientClick="return confirm('Do you want to delete?') but here already OnClick,How can i do this ?

My Ajax Function

 html += '<td>' + '<input type="button" value="Delete" onclick="deleteUploadFile(this,' + value.Id + ')">' + '</td>';

DeleteUploadedFile Function

function deleteUploadFile(element, id) {

         debugger;
         var url = '<%= ResolveUrl("/WebMethods.aspx/RemoveUploadedFile") %>'; 

         $.ajax({
             url: url,
             type: "POST",
             data: JSON.stringify({ id: id }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (Result) {
                 /*on success*/
                 $(element).parents('tr:first').remove();
             },
             error: function (e, x) {
                 //alert(x.ResponseText);
             }
         });
         }

Upvotes: 0

Views: 254

Answers (1)

Jayesh Chandrapal
Jayesh Chandrapal

Reputation: 684

Write your confirm inside your function:

function deleteUploadFile(element, id) {

     debugger;
     var url = '<%= ResolveUrl("/WebMethods.aspx/RemoveUploadedFile") %>'; 

     if(confirm('Deleting file. Are you sure?')) {
         $.ajax({
             url: url,
             type: "POST",
             data: JSON.stringify({ id: id }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (Result) {
                 /*on success*/
                 $(element).parents('tr:first').remove();
             },
             error: function (e, x) {
                 //alert(x.ResponseText);
             }
         });
     }
}

Upvotes: 3

Related Questions