Javascript delete confirmation in Gridview or Repeater

A pretty common task needed within a gridview or repeated is to confirm an action when the user clicks on this. (typically a delete)

The solution to this is pretty simple.  Simple add the following code to the control tag. OnClientClick='return confirm("Are you want to delete this ?");'

An example template field in a Gridview would look something like this <asp:TemplateField> <ItemTemplate> <asp:LinkButton CommandArgument='<%# Eval("ItemId") %>' CommandName="DeleteItem" Text="Delete" runat="server" OnClientClick='return confirm("Are you want to delete this Item?");' /> </ItemTemplate> </asp:TemplateField>

POSTED BY Divergence Hosting on Mar 8 under ASP.NET, Javascript

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

2 Comments so far
  1. JJ March 15, 2009 4:52 am

    Thanks for this, but how do I do this if I want to add the name of the item I want to delete?

  2. Jose September 9, 2009 11:55 am

    Here is a method that creates a custom field. Great for resuse and simple…

    http://csaspnet.blogspot.com/2009/08/aspnet-gridview-confirm-delete-button.html

Copyright Divergence Hosting Technical Blog | Powered by WordPress | Using the GreenTech Theme

SEO Powered by Platinum SEO from Techblissonline