Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a delete button in my gidview ,when i click in it it delete the row.
now i want to add confirmation for the delete operation with 'yes' or 'no' button.i want to do it with javascript.any one please help me

i dont know whether javascript os better method or any one else.

Thanks in advance.
Posted
Updated 13-Jun-12 0:19am
v2
Comments
Sandeep Mewara 13-Jun-12 4:58am    
You are talking of ASP.NET, you should tag correctly.

For adding a delete prompt on a datatable (looks like its going to be a datagrid in UI), you would need to bind the javascript to prompt for this alert during the ItemDataBound/RowDataBound event of the datagrid.

In this event, while the data is binded row by row - add something like:
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " +
    "confirm('Are you sure you want to delete this record')"); 


Alternatively,
if the link button in ItemTemplate of datagrid has OnclientClick event exposed (which is present in ASP.NET2.0 onwards), you can add something like:
OnClientClick = 'return confirm("Are you sure you want to delete this entry?");' 


Refer: MSDN: Adding Client-Side Confirmation when Deleting[^]

Try!
 
Share this answer
 
It has been done so many times before. I you would have searched on Google, it's very likely that you would have got your answer by now.
Anyways, Look at followingt links:

GridView Delete, with Confirmation[^]

http://www.techtoolblog.com/archives/adding-a-confirm-javascript-popup-to-net-gridview[^]
 
Share this answer
 
Please go through below link, simple and easy to understand.

http://forums.asp.net/t/1684080.aspx/1[^]
 
Share this answer
 
hi subin,

in delete button or link button you can add following code

OnClientClick="javascript : return confirm('Do you really want to \ndelete the item?')";
 
Share this answer
 
XML
<asp:TemplateField HeaderText="Delete">
                                                                   <ItemTemplate>
                                                                       <asp:ImageButton ID="btngvresultexclusion" Width="12px" runat="server" ToolTip="Delete"
                                                                           CommandName="Delete" ImageUrl="../Images/Deleting.png" />
                                                                       <AjaxToolkit:ConfirmButtonExtender ID="cbegvresultexclusion" runat="server" ConfirmText="Are you sure you want to delete This Exclusion?"
                                                                           TargetControlID="btngvresultexclusion">
                                                                       </AjaxToolkit:ConfirmButtonExtender>
                                                                   </ItemTemplate>
                                                               </asp:TemplateField>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900