Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vold Hooker 15 posts 35 karma points
    Aug 03, 2010 @ 15:40
    Vold Hooker
    0

    Front end xsl macro menu not refreshed on update

    Umbraco 4.5.1.Relatively new to .net world, coming from a Java background.

    My scenario is that I have some xsl packed into a macro that displays a menu on the front end. The menu displays a red icon if the item displayed needs revision, and a green one if it doesn't.

    From the front end it is possible to set this "revisionRequired" property through a .net user control I've made.

    Everything works fine, except the menu isn't updated until I manually do a page refresh. Caching is off for macro.

    Document is refreshed, published, document cache refreshed and just about everything else I can think of.

    I don't want to make an ugly redirect as that is a hack for sure. Any other suggestions?

  • Sascha Wolter 615 posts 1101 karma points
    Aug 03, 2010 @ 16:29
    Sascha Wolter
    0

    Have you thought about writing a bit of Javascript that will do the modification to the menu, just for the case when it needs updating from the .Net control?

    Otherwise I guess you would have to play around with some AJAX like functionality anyway, like an UpdatePanel, because the XSLT script will not be automatically re-run, which means you would need some kind of trigger to reload the menu just on the client side. E.g. if you have your menu in a div with id 'menu' you could make a jquery call to load in the updated menu:

    $("#menu#).load("/menu");

    The menu template would then just contain the inner menu workings. However if you can achieve this by just adding the icon over the menu item with a simple javascript call that would be preferable I guess.

  • Vold Hooker 15 posts 35 karma points
    Aug 04, 2010 @ 08:47
    Vold Hooker
    0

    Hello Sascha,

     

    Thanks for your response. The javascript would require some time to develop, as in the XSL I am checking for nodes/subnodes recursively, to see if there are any nodes that need to be revised. If there are any at all, then the flag is set. Doing this through javascript as well is twice the work, but I gather it is a possible workaround.

    With regards to ajax, do you know if it is possible to only load a specific macro and then output the result? That would be what is desired.

    I guess the original question remains: why does it take a reload after a post to refresh xsl based output?

  • Sascha Wolter 615 posts 1101 karma points
    Aug 04, 2010 @ 12:13
    Sascha Wolter
    0

    Hi Vold,

    completely agree, you don't want to go down the custom JS route if there is more logic involved that wouldn't belong in the JS script anyway.

    You could implement the ajax stuff in the following way: create a new doc type ('menu') and a template for it as well. Create a new node of type menu directly under the root of your web application (the location doesn't matter though). In the template remove all master references and put your macro on it, so it basically looks something like

    <%@ Language="C#"  %>

    <umbraco:Macro Alias="Menu" runat="server"></umbraco:Macro>

    On your site you would then have e.g. in the master template a div as placeholder for the menu, e.g.

    ...
    <div id="menu">
      <umbraco:Macro Alias="Menu" runat="server"></umbracoMacro>
    </div>
    ...

    As long as you don't need to update the menu on the client side that will work just fine without any ajax invervention. Now whenever you need to update the menu you can do something like

    <script type="text/javascript">
      $("#menu").load('/menu');
    </script>

    This will basically load the content of the /menu page inside of the divs, and the content is exactly the output of your menu macro as described above. Obviously you would need to hook the JS snippet to whenever you are done with your .Net control, e.g. by putting it in response.write("...").

    As to the question of why I don't really know to be honest. I would have though that all .Net stuff is executed first and then the Xslt transformations get applied. However it might be that the page's .Net code gets executed first, then the Xslt and only after that your .Net control. I guess it depends upon how this implemented in the backend and I'm afraid I don't have any insight into that, though I would be really keen to know that as well (before I run into the same problem you have now that is).

    Hope that makes sense,

    Sascha

  • Vold Hooker 15 posts 35 karma points
    Aug 04, 2010 @ 12:18
    Vold Hooker
    0

    Hi Sascha,

    Thank you for your detailed response - it is appreciated.

    Your workaround to this problem seems quite doable. I'll look into implementing it and get back to you on the results :O).

Please Sign in or register to post replies

Write your reply to:

Draft