C# 在jquery页面加载事件上显示按钮不起作用

C# 在jquery页面加载事件上显示按钮不起作用,c#,jquery,asp.net,C#,Jquery,Asp.net,我正在jquery页面加载事件上显示按钮,但它不工作。呈现页面后,该页面不可见 如果我在代码隐藏页面加载事件中设置可见性,效果会很好 Jquery function pageLoad() { $('#btnSwitchDistributor').css({ 'visibility': 'visible', 'display': 'inline-block' }); } Html <asp:Button ID="btnSwitchDistributor" runat="server"

我正在jquery页面加载事件上显示按钮,但它不工作。呈现页面后,该页面不可见

如果我在代码隐藏页面加载事件中设置可见性,效果会很好

Jquery

function pageLoad() {
   $('#btnSwitchDistributor').css({ 'visibility': 'visible', 'display': 'inline-block' });
}
Html

<asp:Button ID="btnSwitchDistributor" runat="server" Text="Switch Distributor" Visible="false" />

,当您在服务器端代码中设置
Visible=“false”
时,元素根本不会呈现给客户端。这意味着您的按钮在结果页面上不是“不可见”的,它在结果页面上不存在。任何JavaScript代码都不能与不存在的元素交互

听起来好像您想对控件应用样式:

<asp:Button ID="btnSwitchDistributor" runat="server" Text="Switch Distributor" style="display:none;" />

  • 您是否在JavaScript代码中调用过
    pageLoad()
    ?如果不是的话,那你就得这么做。我想是吧?对于jQuery,它可能非常简单:
    $(pageLoad)

  • 只需删除visible html属性和JQuery css即可