Call jQuery __doPostBack on LinkButton

I have a LinkButton that I need to click to trigger a postback. Actual target of the link:

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

Clicking a link performs a postback, as verified by a breakpoint in the code. Also inserting javascript:__doPostBack('ctl00$c1$btnRefreshGrid','')into the address bar of the browser works with the same effect.

I tried the following without any effect:

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

I tried to use <%= btnRefreshGrid.UniqueID %>and <%= btnRefreshGrid.ClientID %>to create a selector.

+5
source share
5 answers

You were close, this works in Firefox:

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

( asp: LinkButton ) li

<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, '');

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

Must work...

Hope this helps !!!

0
source

In firebug you can get the correct name and link to the link button:

<a id="MainContent_ctl00_Submit_Button" href="javascript:__doPostBack('ctl00$MainContent$ctl00$Submit_Button','')"></a>
0
source
var Eventtarget = $("#btnSave").attr("name");
__doPostBack(Eventtarget, "");
0
source

All Articles