<p>I have a <code>GridView</code> control in an Asp.net application, that has a <code>&lt;asp:buttonField&gt;</code> of <code>type="image"</code> and <code>CommandName="Delete"</code>.</p>

<p>Is there any way to execute a piece of javascript before reaching the <code>OnRowDelete</code> event?</p>

<p>I want just a simple confirm before deleting the row.</p>

<p>Thanks!</p>

<p><strong>EDIT</strong>: Please Note that <code>&lt;asp:ButtonField&gt;</code> tag <strong>does not have</strong> an <code>OnClientClick</code> attribute.</p>

I would use a TemplateField instead, and populate the ItemTemplate with a regular asp:Button or asp:ImageButton, depending one what is needed. You can then execute the same logic that the RowCommand event was going to do when it intercepted the Delete command.
On either of those buttons I would then use the OnClientClick property to execute the JavaScript confirm dialog prior to this.
```
```
<script type="text/javascript">
   function confirmDelete()
   {
       return confirm("Are you sure you want to delete this?");
   }
</script>

...

<asp:TemplateField>
  <ItemTemplate>
     <asp:ImageButton ID="DeleteButton" runat="server"
        ImageUrl="..." AlternateText="Delete" ToolTip="Delete"
        CommandName="Delete" CommandArgument='<%# Eval("ID") %>'
        OnClientClick="return confirmDelete();" />
  </ItemTemplate>
</asp:TemplateField>
```
```