jQuery 在 LinkButton 上调用 __doPostBack
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3406960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery call __doPostBack on LinkButton
提问by Mark Richman
I have a LinkButton that I need to perform a click on to cause a postback. The actual link target is:
我有一个 LinkButton,我需要点击它来引起回发。实际的链接目标是:
javascript:__doPostBack('ctl00$c1$btnRefreshGrid','');
javascript:__doPostBack('ctl00$c1$btnRefreshGrid','');
Clicking the link does perform the postback, as verified by a breakpoint in the code-behind. Also pasting javascript:__doPostBack('ctl00$c1$btnRefreshGrid','')
in the address bar of the browser works with the same effect.
单击链接确实会执行回发,正如代码隐藏中的断点所验证的那样。javascript:__doPostBack('ctl00$c1$btnRefreshGrid','')
在浏览器的地址栏中粘贴也具有相同的效果。
I've tried the following with no effect at all:
我已经尝试了以下没有任何效果:
__doPostBack('ctl00$c1$btnRefreshGrid','');
$('#ctl00$c1$btnRefreshGrid').click();
$('#ctl00$c1$btnRefreshGrid').trigger('click');
eval($('#ctl00$c1$btnRefreshGrid').attr("href"));
I've tried using both <%= btnRefreshGrid.UniqueID %>
and <%= btnRefreshGrid.ClientID %>
to generate the selector.
我试过同时使用<%= btnRefreshGrid.UniqueID %>
和<%= btnRefreshGrid.ClientID %>
来生成选择器。
采纳答案by Markive
You were close, this works in Firefox:
你很接近,这在 Firefox 中有效:
function clickMyButton() {
javascript:__doPostBack('<%= MYBUTTONID.UniqueID %>','')
};
回答by Iman
the following works for the following anchor (originally asp:LinkButtonin server side) inside li
以下适用于li 内的以下锚点(最初是服务器端的asp:LinkButton)
<li>
<a id="ctl00_ContentPlaceHolder1_ChangeNumberItemGrd_ctl01_FindByID" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ChangeNumberItemGrd$ctl01$FindByID','')">287573</a>
</li>
because i do not have the name i must generate it from it
因为我没有名字我必须从中生成它
$(".msglist li").on("click", function () {
var postbackArg = $(this).find("a").prop("id").replace(/_/g,"$");
__doPostBack(postbackArg, '');
});
回答by Marco Castelo
In firebug you can get the correct name and link action of the link button:
在 firebug 中,您可以获得链接按钮的正确名称和链接操作:
<a id="MainContent_ctl00_Submit_Button" href="javascript:__doPostBack('ctl00$MainContent$ctl00$Submit_Button','')"></a>
回答by jibboo
var Eventtarget = $("#btnSave").attr("name");
__doPostBack(Eventtarget, "");
回答by Carlos Mendible
$("#<%= btnRefreshGrid.ClientID %>").click();
Should work...
应该管用...
Hope it helps!!!
希望能帮助到你!!!