View Single Post
Old May 10th, 2007, 04:22 PM
Scott663 Scott663 is offline
Authorized User
Join Date: Mar 2007
Location: , , .
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
Default GridView Delete Event fires twice

I'm building a site from scratch based on TBH and have been pulling my hair out for nearly 2 days on this one! I added several records to a GridView and then deleted the last record using the delete button (trashcan) and 2 records were deleted. I thought maybe I double-clicked, so I hit delete again and 2 more rows were deleted!

Turns out the problem is cause by a bug in the GridView control that occurs when the delete command is configured to use an image button causing the delete event to fire twice.

I also tested directly on TBH site and the delete event fires twice. Normally you would not be aware of this unless you put a break in the delete method, or happen to notice that several rows were deleted simultaneously.

Even thought the delete always fires twice, sometimes only one row is actually deleted as expected. It appears that multiple rows are only deleted after adding several new rows, and then deleting one of the newly added rows. This is probably why this bug is not encountered more often.

I found several workarounds, one suggests using a Template Field instead of a Command Field if an image button must be used, but I did not actually test. I just changed delete command to a standard button and it works as expected.

Always a fun to encounter this stuff when trying to learn something new!

- Scott.