Ok, so the way this works?
In near "every" case, using some jQuery.UI dialog, sweetalert and in 99% of cases?
These jQuery and JavaScript add-ins ALL, and in ALL cases have one huge "similar" aspect:
that is the code does not wait, nor block the calling code.
The technical term for this type of code is what we call asynchronous.
In a nut shell, WHEN you call such code, the prompt dialog or whatever WILL display, but the code does NOT halt. The routine you call will 100% RUN though its code, display the dialog or whatever and THEN 100% finish, exit and return the value.
The reason for such code is to NOT freeze up the browser, not damage the re-plot, and display of information.
As a result, about the only two commands in JavaScript that actually halt code is
"alert()", and confirm().
The above two commands will halt code. Thus, your question:
You have a plane jane button, and say some code to delete or perform a damaging option, then we all wired up code like this:
<asp:Button ID="cmdDelete" runat="server" Text="Server delete prompt"
OnClientClick="return confirm('Really delete this file?');" />
And, as we know, if user hits cancel, then the button code does not run.
However, what about those js add-ins, and fancy dialogs? Well, they do NOT wait.
I don't have your particular js add-in, but since we all use jQuery, then I give an example how to do this with jQuery.UI.
So, we take the above button, and now do this:
<asp:Button ID="cmdTest" runat="server" Text="Server Delete Prompt"
ClientIDMode="Static"
OnClientClick="return mydeleteprompt(this)"/>
Now, in above, we call a routine, and it will "display" our dialog prompt. But remember that rule above: The code FLOWS though, does not halt the calling js code.
So, what we need to do is STILL RETURN false the first time. (and now our cool prompt dialog is displayed.
the way to make this work? Well, in above we pass "this". In this context, "this" is the current button. So, our code now looks like this:
<div id="MyDialog" style="display:none">
<h4><i>my cool dialog text</i></h4>
<h4><i>This delete can't be undone</i></h4>
</div>
</div>
<script>
var mydeleteok = false
function mydeleteprompt(cmdBtn) {
if (mydeleteok) {
return true
}
myDialog = $("#MyDialog")
myDialog.dialog({
title: "Delete the whole server system",
modal: true,
appendTo: "form",
buttons: {
ok: function () {
myDialog.dialog('close')
mydeleteok= true
$(cmdBtn).click()
},
cancel: function () {
myDialog.dialog('close')
}
}
})
return false
}
Note VERY - but super duper close in above. The routine will return false. That means you click on the button, call the js routine, dialog is displayed, AND THEN FALSE is returned.
Now, the dialog is displayed. If you hit ok button, we set our variable = true AND THEN click the button again!!!!
This time, the same routine will run, but we set our "flag" = true, and the code runs, and returns true, and our server side button code will run.
It will look like this:

So, user click on button, code runs, display dialog, returns "false".
Now, if the user hits "ok", then we run this code:
buttons: {
ok: function () {
myDialog.dialog('close')
mydeleteok= true
$(cmdBtn).click()
},
So, what happens is we set our flag = true, and then click the button again!!! This time, the button calls our routine, but this time the routine WILL return true, and now our server side code for that button will run.
So, your HUGE issue and problem? Near 100%, if not all JavaScript code these days runs asynchronously. It does NOT WAIT.
So, there are advanced concepts such as "await" and things like JavaScript "promise", but it still DOES NOT solve this issue.
So, the asp.net button click event, and using onclientclick is a great feature, but it tends to break down a bit when you want to use some type of dialog "add-in", since as I stated, NONE of them wait. So, you have to adopt the above concept, set a flag (that flag code ONLY runs on page load - first time.
In fact, one could make the case that after I use the .click() to run that button, I probably should set that flag = false again. However, since that server side button is causing a post-back, then in most cases, our flag will be re-set to false.
Edit: Example with jquery-confirm.
As noted, I never used that confirm library (there is about 1+ million of them to be found - you should perhaps have provide a link).
Regardless, that dialog works like this:
<asp:Button ID="Button1" runat="server" Text="Button" CssClass="btn"
OnClick="Button1_Click"
OnClientClick="return myconfirm(this)"
/>
<script>
var myconfirmok = false
function myconfirm(btn) {
if (myconfirmok) {
return true
}
$.confirm({
title: 'Confirm!',
content: 'Simple confirm!',
buttons: {
confirm: function () {
myconfirmok = true
$(btn).click()
},
cancel: function () {
console.log("user hit cancel")
}
}
});
return false // routine MUST return false!!!!
}
NOTE very careful in above - we return false on the last line!!!
So, button is clicked , client side code runs, displays dialog, returns false.
Now, user either hits cancel button, or hits confirm. If they hit confirm, we set our flag = true, and then click the button passed again. Now, our routine runs again, and returns true this time, and thus your server side code now runs.
Edit3: - the issue is use of LinkButton
The issue here is that to use jQuery (or even JavaScript) to CLICK a link button?
You have to use this:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("HotelName") %>' >
</asp:TextBox>
<asp:LinkButton ID="cmdDel" runat="server" ClientIDMode="Static"
CommandArgument='<%# Eval("ID") %>'
onclick="cmdDel_Click"
OnClientClick="return myconfirm(this)"
>delete</asp:LinkButton>
<br />
</ItemTemplate>
</asp:Repeater>
<script>
var myconfirmok = false
function myconfirm(btn) {
if (myconfirmok) {
return true
}
$.confirm({
title: 'Confirm!',
content: 'Simple confirm!',
buttons: {
confirm: function () {
myconfirmok = true
$(btn)[0].click()
},
cancel: function () {
console.log("user hit cancel")
}
}
});
return false // routine MUST return false!!!!
}
</script>
So, you have to address the click even with [0].
Of course, I never use a link button - I useally just drop in a standard button, and there not a whole lot of reason to use a Linkbutton. But, the issue was and is use of jQuery.Click - it needs that [0] for the click event to work.
The code behind for my linkbutton click event is this:
Protected Sub cmdDel_Click(sender As Object, e As EventArgs)
Dim cmdDel As LinkButton = sender
Dim intPKID As Integer = cmdDel.CommandArgument
Debug.Print("code here to delete row with PK id = " & intPKID)
' get current repeater row
Dim OnerepRow As RepeaterItem = cmdDel.NamingContainer
Debug.Print("Repeter index row click = " & OnerepRow.ItemIndex)
' get hotel name texgt box
Dim txtHotel As TextBox = OnerepRow.FindControl("TextBox1")
Debug.Print(txtHotel.Text)
End Sub
And when I run it
