<script type="text/javascript">
jQuery(document).ready(function () {
// note: the `Delete` is case sensitive and is the title of the button
var DeleteButtons = jQuery('#<%= gvShoppingCart.ClientID %> :button[value=Delete]');
DeleteButtons.each(function () {
var onclick = jQuery(this).attr('onclick');
jQuery(this).attr('onclick', null).click(function () {
if (confirm("Are you sure you want to delete item from shopping cart?")) {
return onclick();
}
else {
return false;
}
});
});
});
</script>
How can I change the above code to return the method below if true (instead of onclick())
protected void gvShoppingCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//code here
}
EDIT: new code below –
<script type="text/javascript">
jQuery(document).ready(function () {
$('.deleteStyle').click(function () {
return confirm("Are you sure you want to delete");
});
});
</script>
<style type="text/css">
.deleteStyle
{
}
</style>
Gridview Delete:
<asp:CommandField ControlStyle-CssClass="deleteStyle" ShowDeleteButton="True" ButtonType="Button" />
gvRoles_RowDeleting (Note I am testing it out on Roles Gridview Now!)
protected void gvRoles_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
BusinessLayer.Roles rls = new BusinessLayer.Roles();
rls.deleteRole(rls.getRole(gvRoles.DataKeys[e.RowIndex].Value.ToString()));
this.BindRoles();
}
If you’re determined to use jQuery here’s a simple example:
Example 1:
Please note for this example you should remove
ButtonType="Button"from the CommandFieldExample 2:
This example shows you how achieve the same functionality using
ButtonType="Button":Just change the grid view id’s to the required value;