0

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. 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:

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. And while writing this I thought it was a page-life cycle problem, since the cart credit is being checked OnInit. But even though I changed it to PageLoad, no difference.

Any wise people out there see my problem?

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
Camathon
  • 514
  • 2
  • 5
  • 22

1 Answers1

0

You're just attaching to the wrong method.

Instead of ScriptManager.RegisterClientScriptBlock, use ScriptManager.RegisterStartupScript.

Also, enclose your script with $(function () { }) so it will be executed when the page is fully loaded.

Should solve your problem.

emerson.marini
  • 9,331
  • 2
  • 29
  • 46
  • And what will be after UpdatePanel refresh? – VikciaR Jul 25 '13 at 12:45
  • I can't remember from the top of my head, as I've been working on MVC for a while. Would you mind testing it? – emerson.marini Jul 25 '13 at 12:47
  • Yes thank you, I just came to that conclusion on my own and was about to answer my own question ;) – Camathon Jul 25 '13 at 12:49
  • @VikciaR Updatepanel refresh wont be a problem since the type being called is the update panel and not the Page. As in: ScriptManager.RegisterStartupScript(CartUpdPanel, CartUpdPanel.GetTy.... CartUpdPanel being the updatepanel! – Camathon Jul 25 '13 at 12:50
  • No, I mean that after UpdatePanel you need reapply jquery.button. How to do it? http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels – VikciaR Jul 25 '13 at 12:51
  • I think it would work perfectly, because on that other post, the OP is having a problem with scripts added to the page (like static). Here, it's being registered on every `PostBack`. – emerson.marini Jul 25 '13 at 12:53