I have created a confirmation box that works as expected and return true/false on the button click. But it is a general confirm
where I cannot set a custom title.
function Validate() {
if ($('#cphBody_gvBins').find("input[value='Edit']").length > 0 || $('#cphBody_gvBins').find("input[value='Update']").length > 0 ) {
var mConfirm = confirm("The Record contains data that will be deleted. Do you still want to proceed?");
return mConfirm;
}
}
I call it on a client event. The function returns true or false.
<asp:Button ID="btnIssuerRemove" runat="server" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
CausesValidation="false" CommandName="Remove" Text="Remove" OnCommand="issuerCommand_Click" OnClientClick="return Validate()"/>
But, it is just a regular confirmation box.
So, I went ahead and created a div:
<div id="dialogBox">
Are you sure?
</div>
And then I changes the function to display my div
as a dialog:
function CheckForBins() {
if ($('#cphBody_gvBins').find("input[value='Edit']").length > 0 || $('#cphBody_gvBins').find("input[value='Update']").length > 0) {
//var mConfirm = confirm("The issuer contains Bins that will be deleted. Do you still want to proceed?");
$("#dialogBox").dialog({
title: "System Message",
modal: true,
resizable: false,
width: 250,
buttons: {
Cancel: function () {
$(this).dialog('close');
},
OK: function(){
$(this).dialog('close');
}
}
});
return false;
}
}
Now, with that set up, when I click the "Remove" button, dialog is displayed. However, it does not do anything on "OK"
How can I return true/false from here, so, I do not delete the record when "Cancel" is pressed and "Delete" when "OK" is pressed.
You didn't post your full
HTML
, so I took some liberties in creating someHTML
content using your ID's provided in your example. Next time, please post your fullHTML
so we can see exactly what you're trying to achieve. Also, it looks like you are usingjQuery
andjQuery UI
Dialog, even though you didn't specifically show us/state this.Below is an example with a test record with the 3 buttons you identify in your
JS
. Upon clicking the Remove button, yourIF
statement checks for the Edit/Update buttons existing, and then allows the confirmation dialog to trigger.Please see further documentation of UI Dialog here: https://jqueryui.com/dialog/#modal-confirmation