views:

1255

answers:

4

A few months ago, I have 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 in April 2007)

or e.g. http://stackoverflow.com/questions/218733/javascript-before-aspbuttonfield-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 no more with my ie (Version: 6.0.2900.2180.xpsp_sp2_qfe.080814-1242) - it always deletes the row. With Opera (Version 9.62) it still works as expeced and described in the msdn article. More surprisingly, on a fellow worker's machine with the same ie version, it still works ("Cancel" will not delete the row).

The generated code looks like

<a onclick="return confirm(...);" href="javascript:__doPostBack('...')">

As confirm(...) returns false on "Cancel", I expect the __doPostBack event in the href not to be fired. Are there any strange ie settings I accidentally might have changed? What else could be the cause of this weird behaviour? Or is this a "please reinstall WinXP" issue?

+1  A: 

Try this :

< asp : LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Delete Id : '<%# (string)Eval('id')%>')" >

< /asp : LinkButton >

Samiksha
A: 

Finally found a solution at http://forums.asp.net/t/1161858.aspx

In that thread, the root of the problem was ultimately assigned to "The cause was McAfee Phising Filter".

I had to replace the evident line

OnClientClick='<%# Eval("id", "return confirm(\"Delete Id {0}?\")") %>'

with this cryptic line (I also had to investigate how to escape curly braces), as "event.returnValue=false; makes a difference":

OnClientClick='<%# Eval("zahlungid", "if(confirm(\"Delete Id {0}?\")==false){{event.returnValue=false;return false;}}else{{return true;}}") %>'
A: 

OnClientClick='<%# Eval("zahlungid", "if(confirm(\"Delete Id {0}?\")==false){{event.returnValue=false;return false;}}else{{return true;}}") %>'

works!!! Thanks alot

mushaib
A: 

Tarnold, thanks a lot! That solved the problem. My code sample below:

OnClientClick="if(!confirm('Delete this record?')) { event.returnValue = false; return false; } else { return true; };"
Chook