简体   繁体   中英

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

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?

I don't think you can get that property in javascript. Because the command argument is passed as the the argument in the doPostBack function. But i think you can change your code like this to decrease the complexity.

<asp:LinkButton ID="lnkBtnRestageAdd" 
                CommandName="Add" 
                CommandArgument='<%#Eval("activation_card_number")%>' 
                runat="server" 
                Text="stage" 
                class="add" 
                OnClientClick='<%#Eval("activation_card_number","javascript:return YourFunction({0});")%>' />

do the stuff that you want to do in the function YourFunction return true if Yes is pressed and return false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM