Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery and trigger a click on a hidden button

Tags:

jquery

asp.net

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?

like image 269
RubbleFord Avatar asked Jul 07 '09 10:07

RubbleFord


2 Answers

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();
like image 175
Anh Hoang Avatar answered Nov 10 '22 02:11

Anh Hoang


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

Or just

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

See Events/Trigger

like image 24
karim79 Avatar answered Nov 10 '22 03:11

karim79