I can not click on the ASP button: if it is hidden using jQuery?

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

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

or

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

However, none of them work for me IF the Visible = "true" button

Here is the button:

 <asp:Button ID="loadCustomerContacts" runat="server" OnClick="loadCustomerContacts_Click" visible="false" />" 
+7
source share
5 answers

If the Visible property is set to false; usually in .net, the control will not be displayed in the HTML output after the page is processed. Therefore, in relation to jQuery, the button does not exist.

You can view the 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.

+17
source

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

+2
source

Gorilla's encoding is right, however, what you can do, 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 displaying the page.

+2
source

When Visible is false, the button does not appear in browsers. If it is not in the browser, it cannot be clicked. Instead of using the Visible attribute, use CssClass to hide it. Create a class like in a stylesheet

 .Hidden { display:none; } 

and then use

 loadCustomerContacts.CssClass = "Hidden" 
+1
source

Probably because the button is never displayed in the page layout, although it exists in the page object hierarchy. Client-side JS code builds on existing markup and has nothing to do with what is available in the ASP page model.

If Visible = false does not work, try adding something like display = none; to the button style? If the button is physically located on the page, but your invisible Javascript method may work.

0
source

All Articles