happysmile
happysmile

Reputation: 7777

OnClientClick="return confirm('Are you sure you want delete');"

I am using this code for confirmation on deletion. When I click on the link button, it asks me for confirmation, but the first time I click OK, the record is not getting deleted (only for the first time).

Thereafter that record gets deleted successfully.

<asp:LinkButton ID="LinkBtnDelete" runat="server" 
OnClientClick="return confirm('Are you sure you want delete');" 
CommandName="Delete">Delete 
</asp:LinkButton> 

Any help would be great, thank you.

Upvotes: 16

Views: 109898

Answers (2)

Bassem Nakhla
Bassem Nakhla

Reputation: 63

<asp:LinkButton ID="LinkBtnDelete" runat="server" 
OnClientClick="return confirm('Are you sure you want delete');" 
CommandName="Delete" CommandArgument="">Delete 
</asp:LinkButton>

you must put CommandArgument so it will work from first time

Upvotes: 3

Praveen Mitta
Praveen Mitta

Reputation: 1508

If the above answers doesn't workout for you then try below code:

<asp:LinkButton ID="LinkBtnDelete" runat="server" 
OnClientClick="if (!confirm('Are you sure you want delete?')) return false;" 
CommandName="Delete">Delete 
</asp:LinkButton>

Upvotes: 31

Related Questions