How do I automatically click a Hyerlink or LinkButton using jQuery
<asp:Hyperlink id="ttt" PostBackUrl="Hut.htm">Click</asp:Hyperlink>or<asp:LinkButton id="ttt" PostBackUrl="Hut.htm">Click</asp:LinkButton>
How do I automatically click a Hyerlink or LinkButton using jQuery
<asp:Hyperlink id="ttt" PostBackUrl="Hut.htm">Click</asp:Hyperlink>or<asp:LinkButton id="ttt" PostBackUrl="Hut.htm">Click</asp:LinkButton>
You can use the jQuery click() function without any arguments to simulate a users click.
The only tricky part with asp.net controls is the ID will be some unwieldy generated ID like ctr_00_0001 so you'll have to use a class to target the button:
<asp:LinkButton id="ttt" PostBackUrl="Hut.htm" CssClass="myButton">Click</asp:LinkButton>
and the jQuery:
$('.myButton').click();
Calling the click event on a LinkButton (renders a html link) will not have much effect unless you have manually defined a javascript click event on it.
You need to execute the content in the href attribute (*javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$phContent$ttt", "", true, "", "", false, true))*):
eval($("a[id*='ttt']").attr("href"))
The code above will evaluate the javascript code in the href attribute and execute it.