ASP.NET GridView Client Side Confirmation On Delete has stopped working, that is - how did it happen?
Several months ago I programmed an ASP.NET GridView with a custom "Delete" LinkButton and Client-Side JavaScript Confirmation according to this msdn article:
http://msdn.microsoft.com/en-us/library/bb428868.aspx (published April 2007)
or for example Javascript before asp: ButtonField click
The code looks like this:
<ItemTemplate>
<asp:LinkButton ID="deleteLinkButton" runat="server"
Text="Delete"
OnCommand="deleteLinkButtonButton_Command"
CommandName='<%# Eval("id") %>'
OnClientClick='<%# Eval("id", "return confirm(\"Delete Id {0}?\")") %>'
/>
</ItemTemplate>
Surprisingly, "Cancel" doesn't work anymore with my ie (Version:) 6.0.2900.2180.xpsp_sp2_qfe.080814-1242
- it always deletes the line. In Opera (version 9.62) it still works as described and documented in the msdn article. More surprisingly, on another work computer with the same version, it still works ("Cancel" will not delete the line).
The generated code looks like
<a onclick="return confirm(...);" href="javascript:__doPostBack('...')">
As confirmation (...) returns false on "Cancel", I expect the __doPostBack event in the href to not fire. Are there any strange settings that I might have changed by accident? What else could be causing this strange behavior? Or is it a "reinstall WinXP" problem?
Finally found a solution at http://forums.asp.net/t/1161858.aspx
In this thread, the root of the problem was eventually assigned "The reason was McAfee Phising Filter".
I had to replace the obvious line
OnClientClick='<%# Eval("id", "return confirm(\"Delete Id {0}?\")") %>'
with this cryptic line (I also had to research how to avoid the curly braces) since "event.returnValue = false; has the value":
OnClientClick='<%# Eval("zahlungid", "if(confirm(\"Delete Id {0}?\")==false){{event.returnValue=false;return false;}}else{{return true;}}") %>'