2

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');
    }
});
ZygD
  • 22,092
  • 39
  • 79
  • 102
  • I am pretty sure CommandArgument is an asp server script feature - it isn't native to browsers, and as such javascript isn't going to work with it. There's a few posts to this effect for related workarounds: http://stackoverflow.com/questions/593039/is-there-a-way-to-set-a-asp-net-buttons-commandargument-in-javascript – Brian Jun 14 '15 at 03:48

1 Answers1

1

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>
Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93