Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't click on an ASP:Button if it is hidden using jQuery?

I have found StackOverFlow answers and other resources saying that you can click on a hidden ASP:Button with jQuery by

$("#<%=HiddenButton.ClientID%>").click();

or

$("#<%=HiddenButton.ClientID%>").trigger("click");

However, neither of these are working for me UNLESS the button is Visible="true"

Here is the button:

<asp:Button ID="loadCustomerContacts" runat="server" OnClick="loadCustomerContacts_Click" visible="false" />"
like image 763
pghtech Avatar asked Mar 11 '11 17:03

pghtech


3 Answers

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="myButton" runat="server" style="visibility: hidden; display: none;" />

Or you can assign it a CSS class that hides it.

like image 74
CodingGorilla Avatar answered Oct 28 '22 16:10

CodingGorilla


You need to add style="display:none" to the button instead of Visible=False

like image 21
WraithNath Avatar answered Oct 28 '22 17:10

WraithNath


Coding Gorilla is right, however, what you can do is instead of setting the Visible property, add this to the tag instead:

style="display:none;"

This will hide the button in CSS instead of not rendering the page.

like image 32
Ryan Hoffman Avatar answered Oct 28 '22 17:10

Ryan Hoffman