I want to delete record from GridView.Before to this ask for confirmation like "Are you sure to delete?"
I used command field in GridView,
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
I wrote a function in javascript
function confirm_Delete()
{
var r = confirm("Are you sure you want to Remove this Record!");
if (r == true)
{
alert("Record Deleted");
return true;
}
else
{
return false;
}
}
How I will call this on delete click. Kindly suggest !
You can't achieve this using the command field, you have to make a template field:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtnDelete" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="javascript:return confirm('Are you sure you want to Remove this Record!');">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
It will behave the same way you are doing currently with the Command Field.
I would do the same as @Muhammad told you, and at the server side code for deleting I would also register an script for showing the "Record Deleted" message, as follows;
public void MethodForDeletingARecord()
{
ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "RecordDeletedMessage", "javascript:alert('Record Deleted');", true);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With