I’ve just spent the whole morning trying to get to the bottom of some really strange page behaviour on my current project. I have a gridview control with a command field being used to fire the RowDeleting event. I noticed that when the delete button was clicked the IsPostback property was returning false. This caused all of my page initiation code to be executed for a second time. After hours of trying to find the problem it turns out this is an ASP.NET 2.0 bug that occurs when the commandfield has a button type of ‘Image’.
<asp:CommandField ButtonType="Image" HeaderText="Delete" ShowDeleteButton="true"
DeleteImageUrl="~/Images/delete.png" />
After changing the attribute to ‘Link’ the IsPostback property correctly returns True. The problem with this solution is that you loose any nice icons being used and are left with text. To fix this you can add an image tag to the DeleteText attribute as shown below:
<asp:CommandField ButtonType=Link HeaderText="Delete" ShowDeleteButton="true"
DeleteText="<img src='Images/delete.png' style='border:none;' />" />
Hope this saves someone a bit of time in the future…