jQuery在LinkBut​​ton上调用__doPostBack

时间:2010-08-04 15:14:39

标签: asp.net jquery postback linkbutton dopostback

我有一个LinkBut​​ton,我需要执行一次点击才能导致回发。实际的链接目标是:

javascript:__doPostBack('ctl00$c1$btnRefreshGrid','');

单击该链接会执行回发,由代码隐藏中的断点验证。在浏览器的地址栏中粘贴javascript:__doPostBack('ctl00$c1$btnRefreshGrid','')也会产生相同的效果。

我尝试过以下操作,完全没有效果:

__doPostBack('ctl00$c1$btnRefreshGrid','');    
$('#ctl00$c1$btnRefreshGrid').click();
$('#ctl00$c1$btnRefreshGrid').trigger('click');
eval($('#ctl00$c1$btnRefreshGrid').attr("href"));

我已尝试同时使用<%= btnRefreshGrid.UniqueID %><%= btnRefreshGrid.ClientID %>来生成选择器。

6 个答案:

答案 0 :(得分:4)

你很接近,这适用于Firefox:

 function clickMyButton() {
   javascript:__doPostBack('<%= MYBUTTONID.UniqueID %>','')
};

答案 1 :(得分:1)

以下内容适用于li内部的以下锚点(服务器端最初为 asp:LinkBut​​ton

<li>
<a id="ctl00_ContentPlaceHolder1_ChangeNumberItemGrd_ctl01_FindByID" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ChangeNumberItemGrd$ctl01$FindByID','')">287573</a>
</li>

因为我没有名字我必须从中生成

$(".msglist li").on("click", function () {    
    var postbackArg = $(this).find("a").prop("id").replace(/_/g,"$");    
    __doPostBack(postbackArg, '');

});

答案 2 :(得分:0)

$("#<%= btnRefreshGrid.ClientID %>").click();

应该工作......

希望它有所帮助!!!

答案 3 :(得分:0)

在firebug中,您可以获得链接按钮的正确名称和链接操作:

<a id="MainContent_ctl00_Submit_Button" href="javascript:__doPostBack('ctl00$MainContent$ctl00$Submit_Button','')"></a>

答案 4 :(得分:0)

var Eventtarget = $("#btnSave").attr("name");
__doPostBack(Eventtarget, "");

答案 5 :(得分:0)

ASP.NET:

<asp:LinkButton ID="btnDelete" runat="server" CssClass="btn-u btn-u-xs btn-u-red"
OnClientClick="return get_confirm(this,event);"> <i class='fa fa-trash-o'> Delete </i> </asp:LinkButton>

JavaScript:

function get_confirm(obj, e) {
e.preventDefault()    
var postbackArg = obj.href.replace("javascript:__doPostBack('", "").replace("','')", "");    

$.confirm({
    title: 'Confirm',
    content: 'Are you sure to delete this item?',
    closeIcon: true,
    buttons: {
        confirm: {
            text: 'Ok',
            btnClass: 'btn-red',
            action: function () {
                __doPostBack(postbackArg, '');
            }
        },
        cancel: {
            text: 'Cancel',
            action: function () {
            }
        }
    }
});

}