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?
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.
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.
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.
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
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
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
Here's what I did to fix it in 4.7.0:
Now use this on your page instead of a normal macro and it should work.
Jeroen
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
is working on a reply...
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.