We help IT Professionals succeed at work.

Javascript Delete Confirmation is posting back

Last Modified: 2013-12-17
I have the have a gridview with the folloiwng command field:
 <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" />

In row_databound I do the following for each row and each delete button:
deleteButton.Attributes.Add("onclientclick","javascript:return confirm(\"Are you sure you wish to delete this record?\")");

When I run the page and press the delete button, the client side script never gets ran.  the page goes throught the postpage and my delete processes are executed?

What am I missing here?
Watch Question

Try this:
deleteButton.Attributes.Add("onclick","javascript:return confirm(\"Are you sure you wish to delete this record?\")");

Open in new window

use "onclick" instead of  "onclientclick"


The "onclick" shows the delete confirmation, but clicking okay in it does do a post back.  My GridView1_RowDeleting is never executed.

Did you add   onrowdeleting="GridView1_RowDeleting"   in the asp: gridview tag?
This one is on us!
(Get your first solution completely free - no credit card required)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.