Cannot pass arguments to OnClientClick javascript

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

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s