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
  • 71,301
  • 29
  • 165
  • 172
Cammy
  • 515
  • 2
  • 5
  • 22
  • Check in resulting html button Id - often asp.net adds container id to control id. – VikciaR Jul 25 '13 at 10:39
  • And also, on postback of update panel, you need to reapply javascript. – VikciaR Jul 25 '13 at 10:40
  • http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels – VikciaR Jul 25 '13 at 10:41
  • @VikciaR Im using ClientID to prevent the weird id that asp.net changes it to, and the problem is ONLY at the first page visit. After postback it actually changes to the right button.. – Cammy Jul 25 '13 at 11:02
  • @Blade0rz Why would you remove C# from the title when its a major part of the question? – Cammy Jul 25 '13 at 11:31
  • @Cammy Because it is already tagged C#. It is primarily about the disappearance of the jQuery UI class therefore I left that in the title for context. – CodingIntrigue Jul 25 '13 at 12:13
  • @Blade0rz Funny how the answer to the question had to do with C#... – Cammy Jul 25 '13 at 12:52
  • Are you sure? How do you know MelanciaUK's answer isn't written in VB? My *opinion* was that your question ASP.NET related, not necessarily C# – CodingIntrigue Jul 25 '13 at 13:00
  • @Blade0rz Well _You_ obvious have no idea. Part of the code I posted in my question is C#, thus why I wrote C# and not VB in the header. – Cammy Jul 25 '13 at 13:53
  • @MelanciaUK I'd like to know your opinion. – Cammy Jul 25 '13 at 13:53
  • In fact, nevermind, just in case you take offense. You were right, I was wrong. – CodingIntrigue Jul 25 '13 at 14:04

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,236
  • 2
  • 28
  • 45
  • 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 ;) – Cammy 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! – Cammy 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