• Status: Solved
  • Priority: High
  • Security: Private
  • Views: 41
  • Last Modified:

Rewrite to Include Confirmation of Delete

I am building this buttong to be rendered on the fly.

I need to provide a confirmation before delete.

Since I am building this on the fly ..not sure.

Please help.

   contact.Delete = "<button id=\"btnDelete\"  class=\"btn btn-danger btn-xs actionButton\"";
  contact.Delete += "onclick=\"javascript:Delete('" + contact.clientxcontactId + "')\";>DELETE</button>";

Open in new window

0
Robb Hill
Asked:
Robb Hill
  • 2
  • 2
  • 2
2 Solutions
 
Leonidas DosasCommented:
Try this bootstrap confirmation button:
<button class="btn btn-default" data-toggle="confirmation">Confirmation</button>

Open in new window

And js code:
JS:
$('[data-toggle="confirmation"]').confirmation({
 btnOkLabel:function(){
//here to delete function
},
btnCancelLabel: function(){
return false;
} 
});

Open in new window

0
 
Robb HillSenior .Net DeveloperAuthor Commented:
how would I build that in the example above...since I have to pass it as html string
0
 
Leonidas DosasCommented:
<script>
var contact=new Object();

 contact.Delete = '<button class="btn btn-default" data-toggle="confirmation">Confirmation</button>';
 

 
 parser=new DOMParser();
 var htmlDoc=parser.parseFromString(contact.Delete, "text/html");
 var buttonElm=htmlDoc.childNodes["0"].children[1].childNodes["0"];
 console.log(buttonElm);
 $('body').append(buttonElm);
 
 
 $('[data-toggle="confirmation"]').confirmation({
 btnOkLabel:function(){
//Here delete function
},
btnCancelLabel: function(){
return false;
} 
});

</script>	

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ryan ChongCommented:
why not just add a confirmation verification in your function: Delete?

like:

function Delete(id) {
    if (confirm("Are you sure want to delete this item: "+id+"?")) {
      alert("deleting..");
      //your stuff
    } else {
      alert("cancelled");
    }
  }

Open in new window

1
 
Robb HillSenior .Net DeveloperAuthor Commented:
this is c# code that creates html for this button to be rendered later.

Please help me build the html as you see in this example.


Thanks,


 private void ExtendData(List<GenericGridData> list)
        {
            string designateString = "";
           
            IContactEntityEditService contactEntityEditService = DependencyResolver.Current.GetService<IContactEntityEditService>();
            List<string> roles = contactEntityEditService.GetContactLinkedEntitiesRoles();

          


            foreach (var contact in list)
            {

                switch (contact.designate)
                {
                    case "Primary":
                        designateString = "<select id='selectDesignate'><option value = ''></option><option value='2' selected='selected'>Primary</option><option value='3'>Secondary</option></select>";
                        break;

                    case "Secondary":
                        designateString = "<select id='selectDesignate'><option value = '1'></option><option value='2'>Primary</option><option value='3'  selected='selected'>Secondary</option></select>";
                        break;

                    default:
                        designateString = "<select id='selectDesignate'><option value = '1' selected='selected'></option><option value='2'>Primary</option><option value='3'>Secondary</option></select>";
                        break;
                
                }
                                
                contact.role = selectlist(roles, contact.role, contact.role);      
                contact.designate = designateString;
                contact.allocation = "<input type='number' step='0.01' value='0.00' placeholder='0.00'  id='txtAllocation'>%</input>";
                contact.Update = "<button id=\"btnUpdate\" class=\"btn btn-primary btn-xs actionButton\"";
                contact.Update += "onclick=\"javascript:Update('" + contact.clientxcontactId + "')\";>SAVE</button>";
                contact.Delete = "<button id=\"btnDelete\"  class=\"btn btn-danger btn-xs actionButton\"";
                contact.Delete += "onclick=\"javascript:DeleteContactEntity('" + contact.clientxcontactId + "')\";>DELETE</button>";
            }

              
        }

Open in new window

0
 
Ryan ChongCommented:
i guess you need to enhance the existing javascript function: DeleteContactEntity instead of touching your existing C# codes above.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now