GridView RowCommand firing twice

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • John007
    New Member
    • May 2007
    • 4

    GridView RowCommand firing twice

    I am using a GridView in ASP.Net 2.0 to Insert, Edit, Update and Delete. I am using ItemTemplate and EditItemTemplat e and the buttons are LinkButtons. I am inserting a new row from the footer. The RowCommand event is firing twice when I hit the Edit, Update, Delete and Insert buttons. The AutoEventWireup is set to false. What am I missing? Thanks.
    Last edited by Frinavale; Jan 9 '09, 02:33 PM. Reason: Moved to ASP.NET forum
  • Mimix
    New Member
    • Jun 2007
    • 1

    #2
    I have a solution to this issue that is probably the cleanest I have seen. I will allow you to make the fewest changes to your code and continue using the RowDeleting and RowDeleted events for the GridView.
    Currently when you build a command field for a delete button it will look something like this.
    <asp:CommandFie ld ButtonType="Ima ge" DeleteImageUrl= "images/delete.gif" ShowDeleteButto n="true" />
    By Changing the ButtonType to "Link" and modifying the DeleteText you will have the same delete image that works exactly like the Image Button Type but without the double firing event. Here is the modified code.
    <asp:CommandFie ld ButtonType="Lin k" DeleteText="<im g src='images/delete.gif' alt='Delete this' border='0' />" ShowDeleteButto n="true" />
    Additionally, I am constantly being asked about how to add a confirm dialog box to the delete button. You can use the following code on the RowDataBound event to add the confirmation.

    If e.Row.RowType = DataControlRowT ype.DataRow Then
    Dim lnk As LinkButton = e.Row.Cells(1). Controls(0)
    lnk.OnClientCli ck = "if(!confirm('A re you sure you want to delete this?')) return false;"
    End If
    I hope this helps!

    Comment

    • disa
      New Member
      • Aug 2006
      • 1

      #3
      use this trick



      Change the Button Field as Link Button:

      Button field as Link button and, in the text, set de tag of a html image
      <img src="IMAGENAME" >
      and the event fires one time

      <asp:ButtonFiel d Text="&lt;img src=Images/edit.gif /&gt;" HeaderText="Edi tar" >

      </asp:ButtonField >

      Comment

      Working...