简体   繁体   English

jQuery UI类在按钮上消失了,即使在代码隐藏中设置了.button()?

[英]jQuery UI class dissapears on button even though .button() is set in codebehind?

Im starting to pull my hair over this. 我开始拉我的头发。

Im trying to append jQuery UI's button appearance on my regular button, however it doesn't get appended. 我试图将jQuery UI的按钮外观附加到我的常规按钮上,但是没有附加。 Doesnt even get a class.. 甚至都没有上课..

<asp:UpdatePanel ID="CartUpdPanel" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">
    <button runat="server" ID="CheckoutCartButton" CausesValidation="False" EnableViewState="False">Checkout</button>
    <Triggers>
        <asp:PostBackTrigger ControlID="CheckoutCartButton" />
    </Triggers>
</asp:UpdatePanel>

I want the button to have a secondary icon. 我希望按钮具有辅助图标。 I usually know how to make this happen. 我通常知道如何做到这一点。 But I'm running into problems.. 但是我遇到了问题。

This is the checkout button for my cart (I had the disabling working fine before I wanted to make it look fancy), and in the code behind it checks if you have enough credit to checkout or not, enabling/disabling the button. 这是我购物车的结帐按钮(我想让它看起来花哨之前已经禁用了正常工作),并在其后面的代码中检查是否有足够的信用结帐,启用/禁用按钮。

I cant create the button in a in the ascx file because it will over-write the disabling of the button, making it enabled: 我无法在ascx文件的a中创建按钮,因为它会覆盖按钮的禁用功能,从而使其处于启用状态:

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "disable button", "console.log('disabled'); $('#" + CheckoutCartButton.ClientID + "').button({ icons: { secondary: 'ui-icon-circle-arrow-e' }, disabled: true });", true);

I've tried using the updatepanel's id as control, but to no further success. 我尝试使用updatepanel的ID作为控件,但没有成功。 And while writing this I thought it was a page-life cycle problem, since the cart credit is being checked OnInit. 而且在撰写本文时,我认为这是页面生命周期的问题,因为在InInit上检查了购物车信用额。 But even though I changed it to PageLoad, no difference. 但是,即使我将其更改为PageLoad,也没有区别。

Any wise people out there see my problem? 那里有聪明人看到我的问题吗?

You're just attaching to the wrong method. 您只是在附加错误的方法。

Instead of ScriptManager.RegisterClientScriptBlock , use ScriptManager.RegisterStartupScript . 代替ScriptManager.RegisterClientScriptBlock ,请使用ScriptManager.RegisterStartupScript

Also, enclose your script with $(function () { }) so it will be executed when the page is fully loaded. 另外,用$(function () { })括住脚本,以便在页面完全加载后执行。

Should solve your problem. 应该解决你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM