Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
hello
im new here and this is my first question.i have a gridview with button field delete. it works fine.i want to add a confirmation box using javascript code.i cannot use onclientclick because im not using templatefield.please help.
Posted
Updated 1-Oct-13 21:07pm
v2

hi,
in such cases you need to register the confirmation script on gridview/listview ItemDataBound Event.
Refer to these links will solve your problem.
ASP.NET GridView delete confirmation using asp:CommandField[^]
http://highoncoding.com/Articles/138_GridView_Confirm_When_Delete.aspx[^]
 
Share this answer
 
This is the simplest possible way: http://www.w3schools.com/jsref/met_win_confirm.asp[^].

Alternatively, you can create wonderful and very flexible confirmation dialogs using jQuery. Check it out:
http://myclabs.github.io/jquery.confirm/[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^],
http://learn.jquery.com/[^],
http://learn.jquery.com/using-jquery-core/[^],
http://learn.jquery.com/about-jquery/how-jquery-works/[^] (start from here).

Your question about "onclienclick" looks irrelevant to me, I cannot even understand your idea. You need to get confirmation on the client side anyway. You don't have to use ASP.NET code behind to add an event handler, you generate some HTML, and it can contain any JavaScript.

[EDIT]

In response to the OP's comment to this answers:

The answer is in this comment. Note that his event can be cancelled:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewdeleteeventargs.aspx[^],
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx[^].

—SA
 
Share this answer
 
v2
Comments
Member 10268769 2-Oct-13 3:28am    
im using a gridview button field...ASP.NET GridView delete confirmation using asp:CommandField this link shows it but thats not what im looking for..i have implemented the code in ONROWDELETING event..but befor that event is fired i want a confirmation dialog first.
<asp:imagebutton id="ImageButton1" runat="server">
             ImageUrl ="~/images/grdbtndelete.png" CommandName ="Delete" 
OnClientClick="return confirm("Are you sure you want to delete this entry?");"  />
</asp:imagebutton>
 
Share this answer
 
v2
Comments
Member 10268769 2-Oct-13 4:05am    
im using a button field in my gridview not any image button on itemtemplate.

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