Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 May 10th, 2005, 11:32 PM
Authorized User
 
Join Date: Aug 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to show a confirmation message?

Hi,
i have a datagrid that has delete link,what i want to do is when the user click on the delete he gets a message to ask him if he is sure that he wants to delete this row from the table,is this possible?

 
Old May 11th, 2005, 12:25 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Yes it is possible.Add event for the delete button using [controlname].attributes.add("onClick","javascript:alert('Do you want to delete')").

 
Old May 11th, 2005, 01:06 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Well Santhi, it should be confirm insted of alert. alert will have only one option "OK". The user cannot make a decision. The decision box is confirm
Code:
[controlname].attributes.add("onClick","return confirm('Do you want to delete')").

Regards
Ganesh
 
Old May 11th, 2005, 02:29 AM
Authorized User
 
Join Date: Aug 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes but the button is defined as follows:
<asp:ButtonColumn Text="Delete" HeaderText="Delete" CommandName="Delete" >

and there is no attribute called onclick ,so where shall i add this code?

 
Old May 11th, 2005, 04:50 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Hi Noor ,
    Ganesh is right..YOu should use Confirm instead of Alert.
For adding attributes to the control in datagrid,you have to create ItemCommand event handler for datagrid.Check out the link below..The link has more explanation
http://www.codeproject.com/aspnet/ooaspnet.asp


 
Old May 11th, 2005, 05:03 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Noor,

I think it should be the ItemDataBound or ItemCreated insted of the ItemCommand event.

Regards
Ganesh
 
Old May 11th, 2005, 09:38 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

ItemCommand will only help you if you want to handle things on the postback.

ItemDataBound is where you can add attributes for the client side to controls that will show up for each row in the datagrid.

-Peter
 
Old May 11th, 2005, 09:42 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well that was silly... Sometimes the "Submit Reply" button is just too close to this reply textbox. Accidently submitted before I finished my reply.

In the ItemDataBound handler for the datagrid, you can drill down to the individual controls in each item (e.Item, which is the grid row). You'll know the column number of your buttun column so you can directly access that delete button:

e.Item.Cells(x).Controls(0)

Convert that to a Button object, then you can add an attribute for onClick to it:

CType(e.Item.Cells(x).Controls(0), Button).Attributes("onClick") = ...

Put your confirm javascript in there, and you'll get a confirmation prompt for each delete button in the grid.

Note that you need to test e.Item.ItemType for AlternateItem or Item because that handler gets called for all items including the header, footer and pager and those won't have the delete button.

-Peter
 
Old May 13th, 2005, 11:43 PM
Authorized User
 
Join Date: Aug 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I wrote it in the delete_mydatagrid function as follows:
dim delete as =CType(e.Item.Cells(0).Controls(0), Button).Attributes("onClick") = "javascript:alert('Do you want to delete')"

but gave me an error saying(type expected)
is this the right place and right syntax for the command?

 
Old May 14th, 2005, 08:51 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to put the onClick assignment in the ItemDataBound handler for the grid. This puts the confirm script into the onclick of the delete button for every row. If you do this in the delete handler itself, you'll defeat the purpose altogether because you'll have already arrived back at server-side code where you'll delete the record without prompting the user for delete confirmation.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
webshop email confirmation message Nick23 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 September 14th, 2007 03:43 PM
Message Box (Show if form not filled out) misskaos Classic ASP Basics 38 October 10th, 2006 02:05 PM
Confirmation message on delete of Data grid item hardik@saltriver.com VS.NET 2002/2003 1 December 22nd, 2004 02:27 AM
I cannot disabled show windows message “internet e woland666 Visual C++ 0 June 28th, 2004 05:35 AM





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