JavaScript confirm or radconfirm NOT triggering the PostBack Event

I have a case where I need to add a confirm dialog to the "OnClientClick" event for a WebForms submit button, after adding the confirm dialog, I noticed that the PostBack event of the submit button is not working anymore.

This is the html code that I added to the aspx page, note that the asp.net button is added inside RadAjaxPanel:

<asp:Button ID="btnDelete" runat="server" CssClass="button" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?');"  />

The code looks good but when user clicks the delete button and then confirm the deletion, the PostBack event is not being triggered.

In order to solve this issue that is related to the way of propagating the PostBack event in case of AjaxPanel, I had to modify the code in the OnClientClick as per the following:

<asp:Button ID="btnDelete" runat="server" CssClass="button" Text="Delete" OnClientClick="if (!confirm('Are you sure you want to delete this record?')) return false;"  />

This will solve the issue and if users clicks 'Ok' in the conform window then the PostBack event will be triggered.

This is a short tip for developers who might face similar issue.

YOU MAY ALSO LIKE...

Zender helps you automate marketing emails throughout the customer journey using a powerful API. Create and Send html based emails, Sign Up Confirmation Emails, Change Password Emails, Campaigns, Advertising and Media News Emails

Check out the API http://zender.sharptag.com and let us know how can we support you.

No Comments

Add a Comment

As it will appear on the website

Not displayed

Your website