Alright, so here's the issue at hand:
It seems like you haven't included the JavaScript code for `ShowPopup()`.
However, let's assume that you are utilizing jQuery.UI (dialog) or something similar.
The main problem here is that MOST web code (JavaScript) operates asynchronously. When you click on a button, the client-side code executes, but it DOESN'T HALT or wait like `confirm` does in JavaScript. As a result, even though the dialog appears, the button click still triggers the server-side code stub because your `showpopup()` function doesn't halt. This is true for almost all web code. So, if you're using a bootstrap dialog or, better yet, a jQuery.UI dialog, you'll need to adjust the function call accordingly.
Here's what will happen:
You click on the button. The JavaScript code runs and displays the dialog (returning false so the server-side button code doesn't execute). The user interacts with the dialog - let's say they press "ok" or "confirm". Now, what you need to do is configure that function to return true, then click the button again (in JavaScript), and it will return true or false based on your selection, enabling conditional execution of the server-side button based on that choice.
Below is a functional example using jQuery.UI. Pay attention to how we utilized a boolean flag for this setup.
Therefore, currently we have:
<asp:Button ID="btnDelete" runat="server" Text="Delete"
OnClientClick = "return mydeleteprompt(this)" />
Let's imagine there's a delete button on the page.
This is how our jQuery.UI code would look like:
<script>
mydelpromptok = false
function mydelprompt(btn) {
if (mydelpromptok) {
return true
}
var myDialog = $("#mydelprompt")
myDialog.dialog({
title: "Confirm delete",
modal: true,
width: "320px",
resizable: false,
appendTo: "form",
autoOpen: false,
buttons: {
ok: function () {
myDialog.dialog("close")
mydelpromptok = true
btn.click()
},
cancel: function () {
myDialog.dialog("close")
}
}
})
myDialog.dialog('open')
return false
}
Notice how we set up the function to return FALSE!!! So, when you click on the button, the dialog appears - while we have already returned false!!! Subsequently, when you press "ok" or "confirm" in the dialog, observe how we set that flag to true and CLICK the button again in the JavaScript code. Consequently, when the function runs again, it will return true based on that flag, hence executing the server-side button code. The same approach can be applied to your code too - even though we're not sure how `ShowPopUP` functions, the same methodology can be implemented.
...
(remaining text remains unchanged)
...