Copied to clipboard

Flag this post as spam?

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


  • philw 99 posts 434 karma points
    Apr 18, 2013 @ 10:15
    philw
    0

    Noddy guide to plugging a User Control into Umbraco

    I have a bunch of code and user controls from other sites and projects and I'd like to use some of them in Umbraco. I have searched around here, but I can't find much of a way in.

    I'm using the latest version of Umbraco - 6.something.

    I have lots of user controls, so I'm hoping I can just "lift and shift" the control and maybe the registration line across, then just run the thing. But I can't even work out where to put the control.

    Is there documentation anywhere that tells me how to do this please?

  • Rich Green 2246 posts 4008 karma points
    Apr 18, 2013 @ 10:31
    Rich Green
    1

    Have you tried Umbraco TV?

    Essentially you drop the usercontrols in a Usercontrols folder and then add a new macro and select the usercontrol you want from the drop down.

    Rich

  • philw 99 posts 434 karma points
    Apr 18, 2013 @ 10:33
    philw
    0

    thanks - I tried the TV, but the video was so slow and wanted to tell me how to write user controls - I know all that stuff, I just want to deploy them to umbraco.

    Ok, I'll stick them in the usercontrols folder and google the macro thing down - thanks. 

  • Rich Green 2246 posts 4008 karma points
    Apr 18, 2013 @ 10:34
    Rich Green
    0

    I'm not sure what you mean by 'google the macro thing down'? You just need to select them from the Usercontrol dropdown once you've created a new macro.

  • philw 99 posts 434 karma points
    Apr 18, 2013 @ 10:40
    philw
    0

    "search for and find the instructions for inserting the macro" - which I just did, no problems with that. Should be ok now, thanks.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 18, 2013 @ 10:45
    Lee Kelleher
    100

    Hi Phil,

    Unless you want to pull in Umbraco content into your user-controls, you don't need to go down the Macro route.  Just insert them using <%Register%> declarations:

    <%@ Register Src="~/usercontrols/Whatever.ascx" TagPrefix="noddy" %>
    <noddy:Whatever runat="server" ... />

    Cheers, Lee

  • philw 99 posts 434 karma points
    Apr 18, 2013 @ 10:47
    philw
    0

    That's cool - I thought that should work, but didn't want to thrash around trying too much... I'll give that a go. Thanks

    -- later...

    1. That works fine, I can put code in the template (master page) files that way, and my user controls work, supported by some associated code in App_Code. I just cut and pasted the stuff from another site, dropped it in there as you suggested and it's all good.
       
    2. I also tried the macro route (following this video here: http://www.nibble.be/screencasts/Addingcustomusercontrols.htm), and worked out how to get the macro to show up on the wysiwg editor : you have to tick a dialog box to make it show up there. That doesn't work in Medium Trust, well I think it's a trust issue as when it runs I get a security violation.
    So I think I can put user controls in the templates, but not in the actual content, in my Medium Trust deployment environment. Anyone knows different, please shout! I can work around "user controls can't be inserted by content editors" if I have to, but it would be better to allow them to insert these if I can.
  • Steve Brown 125 posts 290 karma points
    Jun 21, 2013 @ 21:04
    Steve Brown
    0

    philw, did you ever find a way to insert a user control-based macro into a content page? I'm having the same issue in umbraco 6. I'm also using MVC instead of web forms so I'm not sure if it's even possible to use a user control macro

  • philw 99 posts 434 karma points
    Jun 21, 2013 @ 21:09
    philw
    0

    Yes, it's pretty easy - as above. From memory:

    1. Stick user control in the user controls directory
    2. Create a macro and point it at the user control (there are dialog box options for that).
    In practice I found that this wasn't great as I can't render the controls in the UI (I'm on Medium Trust), so I went a different way and equipped my pages with "content" fields which specify which user controls to include in each page. I parse those "content" fields and inject the user controls from C# as I want. This avoids the user having to use un-rendered macros, which are clunky.
    This all on the latest version 6.05 or whatever
Please Sign in or register to post replies

Write your reply to:

Draft