Wrox Programmer Forums
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 18th, 2010, 01:36 AM
Registered User
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delete confirmation on gridview

plz use this in grid view

in aspx page
<asp:CommandField HeaderText="Delete" ButtonType="Link" ShowDeleteButton="True" HeaderStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" ></HeaderStyle>

and .cs page u place this code

protected void GrdCategory1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
foreach (DataControlFieldCell cellll in e.Row.Cells)
{ foreach (Control ccc in cellll.Controls)
LinkButton lkb = ccc as LinkButton;
if (lkb != null && lkb.CommandName == "Delete")
lkb.OnClientClick = "return confirm('First delete all Products Of this subcategory.Are you sure you want to delete?')";


this code absolutely working well!!
Old December 18th, 2010, 03:48 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

I don't see how this helps. First, he's using a DataGrid, not a GridView. Secondly, why go through all the inefficient trouble of looping through all controls while you could use FindControl as in the OP's code, or better yet, just define OnClientClick in the markup?

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Old December 20th, 2010, 06:50 AM
Authorized User
Join Date: Nov 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

Originally Posted by Imar View Post
This doesn't make sense:
onclick="confirm_delete();return false;"
This way, the delete never firer as you always return false. In my case, false is only returned when you don't confirm. If with my code the page still posts back when you cancel, there must be something in your code that you're not showing us.

Did you try the OnClientClick I proposed and deleted your own code that does it programmatically?

Hi Imar,

Sorry for the late response, got called away to help a colleague and spend the better part of the morning to clean up my code a little. Made so many changes to test stuff it became messy and unclear.

Anyways, I tried you onClientClick after removing the part that adds it programmatically, and it's the same problem. I click cancel, the page still posts back (and thus gets redirected when it shouldn't).

<input type="submit" id="ctl00_ContentPlaceHolder1_dgOffertes_ctl03_btnDelete" onclick="if (!confirm('Are you sure?')) { return false };" value="Delete" name="ctl00$ContentPlaceHolder1$dgOffertes$ctl03$btnDelete">
So, I am probably missing something, but since I don't know what, I also don't know what else to tell you that might help.
Old December 20th, 2010, 07:29 AM
Authorized User
Join Date: Nov 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

Okay, I found it!

Somewhere in a massive block of code within the ItemDataBound event it did this:

e.Item.Attributes.Add("onclick",ClientScript.GetPostBackEventReference(e.Item.Controls[1].Controls[0], e.Item.ItemIndex.ToString()));
Which placed a second onclick on the row or something. My colleague and I found it just now as we were cleaning up code left by the previous team.

Anyways, thanks for your help Imar!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Button on a DataGrid Ric_H ADO.NET 1 March 23rd, 2006 06:33 PM
Select Button on a DataGrid Ric_H C# 0 March 22nd, 2006 04:14 PM
Update Button in DataGrid Bibin .NET Framework 1.x 1 January 28th, 2006 08:22 AM
Button in Datagrid rodmcleay C# 1 September 25th, 2005 06:13 AM
button on a datagrid narbones ASP.NET 1.x and 2.0 Application Design 0 June 17th, 2003 07:02 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.