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

LVL 11
Robb HillSenior .Net DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
i guess you need to enhance the existing javascript function: DeleteContactEntity instead of touching your existing C# codes above.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.