I have found * answers and other resources saying that you can click on a hidden ASP:Button with jQuery by
我找到了*的答案和其他资源,说你可以点击一个隐藏的ASP:按钮与jQuery by
$("#<%=HiddenButton.ClientID%>").click();
or
$("#<%=HiddenButton.ClientID%>").trigger("click");
However, neither of these are working for me UNLESS the button is Visible="true"
但是,这些都不适用于我,除非按钮是Visible =“true”
Here is the button:
这是按钮:
<asp:Button ID="loadCustomerContacts" runat="server" OnClick="loadCustomerContacts_Click" visible="false" />"
5 个解决方案
#1
17
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.
如果将Visible属性设置为false;通常在.net中,在处理页面后,控件不会在HTML输出中呈现。因此,就jQuery而言,该按钮不存在。
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:
如果您想这样做,而不是使用Visible属性,您可以执行以下操作:
<asp:Button ID="myButton" runat="server" style="visibility: hidden; display: none;" />
Or you can assign it a CSS class that hides it.
或者你可以为它分配一个隐藏它的CSS类。
#2
2
You need to add style="display:none" to the button instead of Visible=False
您需要在按钮中添加style =“display:none”而不是Visible = False
#3
2
Coding Gorilla is right, however, what you can do is instead of setting the Visible property, add this to the tag instead:
编码Gorilla是正确的,但是,您可以做的不是设置Visible属性,而是将其添加到标记中:
style="display:none;"
This will hide the button in CSS instead of not rendering the page.
这将隐藏CSS中的按钮而不是不呈现页面。
#4
1
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
当Visible为false时,按钮不会在浏览器中呈现。如果它不在浏览器中,则无法单击。而不是使用Visible属性使用CssClass来隐藏它。在样式表中创建一个类
.Hidden {
display:none;
}
and then use
然后使用
loadCustomerContacts.CssClass = "Hidden"
#5
0
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.
这可能是因为按钮永远不会呈现到页面标记中,尽管它存在于页面对象的控件层次结构中。客户端JS代码依赖于现有标记,与ASP页面模型中的可用内容无关。
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.
如果Visible = false不起作用,您是否尝试添加类似“display = none;”的内容按钮的样式?如果按钮实际位于页面上但不可见,则Javascript方法可以正常工作。
#1
17
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.
如果将Visible属性设置为false;通常在.net中,在处理页面后,控件不会在HTML输出中呈现。因此,就jQuery而言,该按钮不存在。
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:
如果您想这样做,而不是使用Visible属性,您可以执行以下操作:
<asp:Button ID="myButton" runat="server" style="visibility: hidden; display: none;" />
Or you can assign it a CSS class that hides it.
或者你可以为它分配一个隐藏它的CSS类。
#2
2
You need to add style="display:none" to the button instead of Visible=False
您需要在按钮中添加style =“display:none”而不是Visible = False
#3
2
Coding Gorilla is right, however, what you can do is instead of setting the Visible property, add this to the tag instead:
编码Gorilla是正确的,但是,您可以做的不是设置Visible属性,而是将其添加到标记中:
style="display:none;"
This will hide the button in CSS instead of not rendering the page.
这将隐藏CSS中的按钮而不是不呈现页面。
#4
1
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
当Visible为false时,按钮不会在浏览器中呈现。如果它不在浏览器中,则无法单击。而不是使用Visible属性使用CssClass来隐藏它。在样式表中创建一个类
.Hidden {
display:none;
}
and then use
然后使用
loadCustomerContacts.CssClass = "Hidden"
#5
0
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.
这可能是因为按钮永远不会呈现到页面标记中,尽管它存在于页面对象的控件层次结构中。客户端JS代码依赖于现有标记,与ASP页面模型中的可用内容无关。
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.
如果Visible = false不起作用,您是否尝试添加类似“display = none;”的内容按钮的样式?如果按钮实际位于页面上但不可见,则Javascript方法可以正常工作。