How can I use CommandArgument of LinkButton in jQuery?

1.8k views Asked by At

I have 5 link buttons. And I want to send their command argument to a web method to load on page scroll.

$.ajax({
    type: "POST",
    url: "Default.aspx/GetCustomers",
    data: '{pageIndex:'+pageIndex+'}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    failure: function (response) {
       alert('Hell 1');
    },
    error: function (response) {
        alert('Hell 2');
    }
});
1

There are 1 answers

0
Mohamad Shiralizadeh On

No you can't use CommandArgument in jQuery because it stores in viewstate of the page. but you can use data-... attribute instead.

<asp:LinkButton ID="btnSave" runat="server" Text="Save" data-id="<%# DataBinder.Eval(Container.DataItem, "ID") %>" />
<script>
    var id = $('#btnSave').data('id');
    // use id
</script>