I have code like this in Page_Load()
btnMainDelete.Attributes.Add("onclick", "if(confirm('Are you sure you want to delete this?')){}else{return true}");
Basically, it's confirming that before deletion (Yes/No). If it's a yes then delete the record and if it's no then do nothing.
For the btnMainDelete, I put as follow:
<asp:Button ID="btnMainDelete" runat="server" Text="Delete" OnClick="btnMainDelete_Click" />
Now the issue is that, what I press Yes or No always executes btnMainDelete_Click
on the server side? I must have something missing here.
Thanks
Put valid confirm script in the OnClientClick:
<asp:Button ID="btnMainDelete" OnClientClick="javascript:return confirm('Are you sure?');" runat="server" Text="Delete" OnClick="btnMainDelete_Click" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With