Copied to clipboard

Flag this post as spam?

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


  • Scott Blomfield 30 posts 57 karma points
    Sep 28, 2009 @ 22:34
    Scott Blomfield
    0

    Have a .NET Usercontrol in the output of an XSLT Macro

    I need a way to be able to have an existing .NET usercontrol (which also has a Macro created for it already) to be able to be in the output of an XSLT macro. I cannot find a way to do this - the usercontrol has an event attached to it, so I cannot make it an xslt macro. The XSLT macro is referencing current node properties, and I have had issues accessing those from .NET before, so  I don't want to make the macro a usercontrol ... does anyone know how I can accomplish this via any means? I heard whisperings of a RenderMacro function, but haven't seen any indication how to use it in v4.0.0.0.

     

    Thanks,

    Scott

  • Paul Sterling 718 posts 1534 karma points MVP 8x admin c-trib
    Sep 28, 2009 @ 23:41
    Paul Sterling
    0

    Scott -

    Since you're using a UC already, have you considered using umbraco.presentation.nodeFactory to access the Node Properties?  We use this extensively in our development and find the reliability and performance to be excellent. 

    -Pauk

  • Shannon Deminick 1525 posts 5271 karma points MVP 2x
    Oct 01, 2009 @ 09:56
    Shannon Deminick
    0

    You can easily write an extension method called 'RenderControl' which takes in a string (the path of your user control), then you can do this in the body of your method:

    UserControl control = new UserControl();
    YourUserControlType template = (YourUserControlType)control.LoadControl(YourUserControlPath);
    //set properties if necessary:
    template.YourProperty = "myvalue";
    return RenderControl(template);

    If you need your User Control to go be able to be process it's page lifecycle, then you need a bit more trickery, or you can create a new Page instead of UserControl to load in your control and run Server.Execute() which will put the control though it's entire page lifecycle... be warned that if you do Server.Execute within Umbraco that it will turn trace=on by default so you'll have to disable trace when you create your page at runtime.

    The above should work for simple user controls, otherwise Server.Execute will work for complex controls.

    We do similar things quite a bit to load user control content into Macro's (when this is necessary)

    RenderMacro might work in the new 4.0.2.1 version but I can't be sure with UserControls as I've not tried. The syntax for using RenderMacro is quite strange (uses old macro syntax),

Please Sign in or register to post replies

Write your reply to:

Draft