I want to give more information to the confirm dialog when the user deletes a record.
I’m using an asp:LinkButton that can execute some javascript when the user clicks it, in the “OnClientClick” property.
<ItemTemplate> <asp:LinkButton ID="lnkClose" runat="server" CausesValidation="False" data-number='<%# Eval("Number") %>' CommandArgument='<%# Eval("Id") %>' CommandName="close" CssClass="selected_item close-project">Close </asp:LinkButton> </ItemTemplate>
Unfortunately, I cannot pass the project number as an argument to the javascript function in OnClientClick.
Luckily, there is jQuery:
$('#ProjectsList a.close-project').live("click", function() { var $parentRow = $(this).parent().parent(); $parentRow.toggleClass("current"); var projectNumber = $(this).attr("data-number"); var answer = confirm("Close project " + projectNumber + "?"); if (!answer) { $parentRow.toggleClass("current"); } return answer; });
Update: There is a way to pass arguments:
http://forums.asp.net/t/980311.aspx/1?Eval+in+an+OnCLientClick