【问题标题】:How can I use CommandArgument of LinkButton in jQuery?如何在 jQuery 中使用 LinkBut​​ton 的 CommandArgument?
【发布时间】:2015-08-29 18:59:34
【问题描述】:

我有 5 个链接按钮。我想将他们的命令参数发送到 web 方法以加载页面滚动。

$.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');
    }
});

【问题讨论】:

  • 我很确定 CommandArgument 是一个 asp 服务器脚本功能 - 它不是浏览器原生的,因此 javascript 无法使用它。有一些关于此效果的相关解决方法的帖子:stackoverflow.com/questions/593039/…

标签: jquery commandargument


【解决方案1】:

不,您不能在 jQuery 中使用 CommandArgument,因为它存储在页面的视图状态中。但您可以改用data-... 属性。

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

【讨论】:

    猜你喜欢
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    • 2016-08-17
    • 2012-12-12
    • 2011-12-31
    • 2011-03-25
    • 1970-01-01
    相关资源
    最近更新 更多