Copied to clipboard

Flag this post as spam?

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


  • Roger Swearingen 28 posts 49 karma points
    Jan 14, 2011 @ 23:30
    Roger Swearingen
    0

    Render UserControl Macro in XSLT

    Hello,

    I have done some searching, but did not find exactly what I am looking for.  I have an existing XSLT macro, which has been able to successfully render the output I need up to this point.  The problem I have now is that I also have a .NET usercontrol in C#, which takes a couple of Umbraco page fields and outputs a specific hash string. 

    I need to insert the string output from the .NET usercontrol into a specific point in my XSLT output (inserting hashed source value into a Silverlight control).  I have a couple ideas around this, but they all seem fairly complicated and I am wondering if there may be simple way to meet my needs.

    Any suggestions?

     

    Thanks in advance,

    jt

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 15, 2011 @ 00:42
    Jan Skovgaard
    1

    Hi Jeff

    Are you sure what you're trying to do can't be achieved building an extension, which can be used in the XSLT instead? Including a User control in a XSLT file does not make sene I think.

    But if you create your own XSLT extension you can pass the values to the XSLT as needed.

    You could also write some inline C# code in the XSLT file if that helps you. You can see an example on how to do that here: http://forum.umbraco.org/yaf_postst2996_Accessing-QueryString-Within-C-Within-XSLT.aspx (nevermind the code - just an example of how you need to markup the section with C# code in the XSLT file).

    If you just need to serve some umbraco properties to your user control I think you should be able to do that setting some properties and then feed them to the macro once it get's inserted. But you can't mix a user control into XSLT.

    /Jan

  • Roger Swearingen 28 posts 49 karma points
    Jan 15, 2011 @ 01:47
    Roger Swearingen
    0

    Thanks Jan for the response.  Since I already have both the XSLT and .NET usercontrol macros working perfectly, I was hoping to keep them intact, but it looks like that's just not going to happen.

    I was under the impression that scripting within XSLT was bad practice, but perhaps I should read more about that.

    I'll also look more into creating an XSLT extension, as it sounds like that might be my best bet.

     

    Thanks

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Jan 15, 2011 @ 03:15
    Lee Kelleher
    1

    Hi Jeff,

    Like Jan suggestions, an XSLT extension sounds ideal for your requirement.

    You're right about inline scripting in XSLT being bad practice - try to avoid that at all costs.  If you do need to write something quick, then put the code/script in your App_Code.

    As for trying to render a .NET-based macro from within XSLT, it doesn't work.  I believe it is to do with the stage that the XSLT is rendered in relation to the ASP.NET page life-cycle - but don't quote me on that, not 100% sure!  All I know is that I've tried it too and it doesn't work! ;-(

    Cheers, Lee.

  • Roger Swearingen 28 posts 49 karma points
    Jan 15, 2011 @ 06:58
    Roger Swearingen
    0

    Thanks for the help guys.  Much appreciated.

  • Roger Swearingen 28 posts 49 karma points
    Jan 15, 2011 @ 11:09
    Roger Swearingen
    0

    Wow. That was so easy!  I just built my 1st XSLT extension and my only question is why didn't I ever do this before?  It does EXACTLY what I needed.  All I keep thinking about now is how many things over the past year I could have done with this.

    For anybody else interested there is a great video on umbraco.tv to get you started, then you just need to plug in your C# code.

    Again, thanks Jan and Lee for pushing me in the right direction.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 15, 2011 @ 11:30
    Jan Skovgaard
    0

    Hi Jeff

    Good to hear you got a revelation on this subject - it's a nice feeling when you get the bricks to fall into place and have another tool in the belt for future projects.

    umbraco.tv is worth the money for sure :-)

    /Jan

  • 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