How to apply javascript on <asp: Buttonfield>?
3 answers
asp: ButtonField> does not have OnClientClick.
Replace with the Templated button
<script type="text/javascript"> function function() { return confirm("Are you sure you want to delete this?"); } </script> ... <asp:TemplateField> <ItemTemplate> <asp:ImageButton ID="button" runat="server" OnClientClick="return function();" /> </ItemTemplate> </asp:TemplateField> +1
I found a pretty simple way to do this when working with jQuery, which meant that I could still use asp: boundbutton
Apply CssClass to 'btn-remove' to the associated button (in this case), then add the following jQuery script
$(function () { $('.btn-remove a').attr('onclick', 'return confirm(\'Are you sure you want to delete this?\')'); }); 0