Encountering an issue with the javascript alert in my ASP.NET application. I have a button that deletes a user from the database. However, users may have associated documents and insurance policies.
I want to trigger a javascript alert if the user has any documents or policies. The alert will prompt: "You need to delete documents and/or policies." If the user does not have any of them, a confirmation box should appear giving you the option to proceed with the deletion.
Here is a snippet of my .aspx code:
<asp:Button ID="btnDelete" class="btn btn-danger" runat="server" Text="Delete" OnClick="btnDelete_Click"
onClientClick="check()">
</asp:Button>
The function check() looks like this:
function check() {
var totalRows = $("#<%=gvDocuments.ClientID %> tr").length-1;
var totalRows1 = $("#<%=gvPolice.ClientID %> tr").length-1;
if (totalRows > 0 || totalRows1 > 0) {
alert('Delete ' + totalRows + ' documents and ' + totalRows1 + ' policies of the client before proceeding with the deletion!');
//Checking if there are any documents or policies
return false;
}
else {
var r = confirm('Are you sure you want to delete the client?');
if (r == true) {
return true;
}
else {
return false;
}
}
}
The confirm block functions correctly. Pressing OK proceeds with the deletion, while Cancel returns false.
My concern is when the user clicks OK on the alert, it triggers a postback and deletes the user without deleting the documents and policies. Is this returning true?
Thank you,
Regards