Copied to clipboard

Flag this post as spam?

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


  • Mike Taylor 155 posts 353 karma points
    Mar 19, 2012 @ 14:11
    Mike Taylor
    0

    XSLT macro rendered before usercontrol postback code is run? Value of session variable not updating...

    I have two macros:

    1) an XSLT macro which displays the value of a session variable

    2) a .NET usercontrol macro which contains a LinkButton which changes the value of the session variable.

     

    When I first visit the page, the XSLT macro displays the correct value. When I click the LinkButton, the page does the postback and the session variable updates (as shown in the trace); however, the XSLT macro still displays the old value of the session variable.

    If I do a manual page refresh, the XSLT updates to show the correct (new) value of the session variable.

     

    Does this mean that XSLT macros render *before* the postback code is run? If so, what is the logic behind that? (Doesn't immediately make sense to me to have it that way round...) Is there any way my XSLT can pick up the new value?

    Thanks,

    Mike

  • Mike Taylor 155 posts 353 karma points
    Mar 20, 2012 @ 13:15
    Mike Taylor
    0

    This is driving me crazy...

    I don't think it's XSLT macros particularly - the same happens with other .NET user control macros. I guess it must be that (other) macros (apart from the one causing the postback) are rendered before postback code is run.

    Has anyone got any workarounds?

    Thanks,

    Mike

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 20, 2012 @ 13:44
    Jeroen Breuer
    1

    I've had the same problem with Razor. Have a look at this topic: http://our.umbraco.org/forum/developers/razor/21722-Set-Razor-macro-parameters-in-code-behind. For Razor they fixed it in 4.7.1. There you can do RenderEvent="PreRender", but I'm not sure if it's fixed for XSLT.

    Jeroen

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Mar 20, 2012 @ 13:52
    Jeroen Breuer
    0

    Here's what I did to fix it in 4.7.0:

    public class RenderMacro : umbraco.presentation.templateControls.Macro
    {
        protected override void OnInit(EventArgs e)
        {
            //Don't do anything in the OnInit. This will be done in the PreRender of the Macro.
            //base.OnInit(e);
        }
    }

    Now use this on your page instead of a normal macro and it should work.

    Jeroen

  • Mike Taylor 155 posts 353 karma points
    Mar 21, 2012 @ 01:21
    Mike Taylor
    0

    Thanks Jeroen - that helped a lot, and worked perfectly on the XSLT macro. I had another .NET macro which I needed to update, and was altogether a more complicated affair but I've got it working now.

    Cheers for your help.

    Mike

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies