简体   繁体   中英

Jquery and trigger a click on a hidden button

I have a hidden button on a form that I need to click in order to fire an asyncpostback trigger that's attached to an update panel.

How is this done?

$('#myHiddenButton').trigger("click");

Or just

$('#myHiddenButton').click();

See Events/Trigger

For the Webform: if you set the Visible property to false; typically in .net the control will not be rendered in the HTML output after the page is processed. Therefore as far as jQuery is concerned, the button does not exist.

You can do a View Source on the page to verify this.

If you want to do this, instead of using the Visible property, you can do something like:

<asp:Button ID="HiddenButtonID" runat="server" style="visibility: hidden; display: none;" />

Then you can using jQuery to click button as :

$("#HiddenButtonID").click(); //Remember that in button, you must set ClientIDMode = "static"

or

$("#<%=HiddenButtonID.ClientID%>").Click();

怎么样

$("#buttonid").click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM