Getting the value from asp:LinkButton's CommandArgument attribute using jquery/javascript

Posted by LobalOrning on Stack Overflow See other posts from Stack Overflow or by LobalOrning
Published on 2011-01-05T16:23:00Z Indexed on 2011/01/05 16:54 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

I need to get the value of the CommandArgument attribute of a LinkButton, in an asp:Repeater.

I have an asp:Repeater with 2 LinkButtons whose CommandArgument I set to a value:

<ItemTemplate>
    <tr class="odd">                                        
        <td><%#DataBinder.Eval(Container.DataItem, "batch_id")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "productId")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "serial_number")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "activation_card_number")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "transaction_amount","{0:C}")%></td>                                        
        <td><%#DataBinder.Eval(Container.DataItem, "response_dt", "{0:M/d/yyyy HH:mm:ss}")%></td>                                        
        <td style="text-align:center;"><%#DataBinder.Eval(Container.DataItem, "resp_process_msg")%></td>
        <td style="text-align:center;"><%#DataBinder.Eval(Container.DataItem, "resp_response_code")%></td>
        <td style="text-align:center;"><asp:LinkButton ID="lnkBtnRestageAdd" CommandName="Add" CommandArgument='<%#Eval("activation_card_number")%>' runat="server" Text="stage" class="add" OnClientClick="return false;" /></td>                                                                                
        <td style="text-align:center;"><asp:LinkButton ID="lnkBtnRestageMinus" CommandName="Subtract" CommandArgument='<%#Eval("activation_card_number")%>' runat="server" Text="stage" class="minus" OnClientClick="return false;" /></td>
      </tr>
</ItemTemplate>

I have suppressed the PostBack with OnClientClick="return false;" so that I can pop a jQuery dialog modal when the link buttons get clicked:

if (btnAdd != null) {
    $(".add").click(function() {
        $("#<%=divDialogAdd.ClientID %>").removeAttr("style");
        $("#<%=divDialogAdd.ClientID %>").dialog("open");
    });
}

In the modal I have 2 other asp:LinkButtons, and when the 'Yes' button is clicked I do the postback like so:

yesBtn.click(function() {
    setTimeout('__doPostBack(\'btnAdd\',\'\')', 0); //need to add a param
});

What I need to do, is somehow grab the CommandArgument value from the LinkButton in the Repeater, so that I can pass that as a parametere or assign it to a hidden field. I have tried jQuery's attr(), but that only works when the attribute was set using that function as well. How can I get this value, or what other way can I go about this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ASP.NET