Here is a sample code how I use javascript confirm on GridView:
<asp:GridView ID="gv" runat="server" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete" runat="server" OnCommand="btnDelete_Command"
CommandArgument='<%# Eval("Id") %>' ImageUrl="~/img/delete.png"
OnClientClick="return btnDelete_Click()"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
function btnDelete_Click() {
return window.confirm('You sure?');
}
</script>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gv.DataSource = list;
gv.DataBind();
}
}
protected void btnDelete_Command(object sender, CommandEventArgs e)
{
// Delete Operation.
}
I hope it will be helpful.