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" />"
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.
You need to add style="display:none" to the button instead of Visible=False
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.
When the Visible is false the button is not rendered in the browsers. If it is not in the browser, it can't be clicked. Instead of using Visible attribute use CssClass to hide it. Create a class like in the stylesheet
.Hidden {
display:none;
}
and then use
loadCustomerContacts.CssClass = "Hidden"
That's probably because the button never gets rendered into the page markup, although it exists in the page object's control hierarchy. Client-side JS code relies on the existing markup and has nothing to do with what's available in the ASP page model.
If Visible=false does not work, have you tried adding something like "display=none;" to the button's style? If the button is physically on the page but invisible your Javascript method could work.