Link to home
Start Free TrialLog in
Avatar of weimha
weimhaFlag for United States of America

asked on

Javascript Delete Confirmation is posting back

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?
                               
Avatar of nivlam
nivlam
Flag of United States of America image

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

Open in new window

Avatar of Amaku
Amaku

use "onclick" instead of  "onclientclick"
Avatar of weimha

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Amaku
Amaku

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial