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 23, 2013 @ 22:30
    philw
    0

    Umbraco 6.0.3 c# userControl, access to public parameters

    I have user controls working from Master Pages, but I'm having problems passing them to the userControl from a Macro: that I cannot get to work.

    • I've tried various ways to declare the parameters: with getters and setters, or without, within a region labeled "properties", pretty much every combination I can think of, but still nothing works.
    • I can manually give the Macro parameters, but these don't become available at the userControl.
    • The "browse public properties" button does appear once I set up a userControl as the target, but there are never any properties in the dialog that button opens, irrespective of how precisely I declare the parameters.
    • I'm trying to pass strings at the moment, which I would hope is simple.
    • I'm checking the values at PreRender, so they should be there by then.
    Does anyone know the secret for this, or have a trivial example I can just load up? I've checked all the posts here and I can't find anything that works.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 25, 2013 @ 09:41
    Dave Woestenborghs
    0

    For using usercontrol macros with parameters you will do this.

    You create a user control with public properties e.g.

    public string MyProperty {get;set;}

    Remember to build your project

    Than you go into the developer section of Umbraco and create a new macro. You choose the ascx files of your user control. Then you can click the button browse properties. This will list all your public properties.

    Another option would be to add them manually. On you macro go to the tab Parameters.

    There you fill in the following fields.

    - Show : does the parameter needs to be shown in the add macro dialog 
    - Alias : the name used in Umbraco
    - Name : the name of your property on the user control
    - Type : choose the editor control that needs to be shown when adding your macro to the template.

    Then click the add button and save your macro.

    Next you will go to settings and then templates. On your template you will need to click the add macro button. This will let you choose your macro and will show a dialog to fill in the properties.

    Dave

     

  • philw 99 posts 434 karma points
    Apr 25, 2013 @ 09:50
    philw
    0

    Thanks - that's pretty much what I'm trying to do. The only differences I can see (so far: I'll look some more), are:

    1. I'm trying to add the user control into content (the Rich Text Editor), not into a Master Page (a Template).
    2. I am running under Medium Trust, which could affect what's possible with for example reflection.
    The symptoms are:
    1. The "browse properties" button shows an empty list when pressed, irrespective of how I define the properties.
    2. If I manually define the properties, they do not "arrive" at the userControl.
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 25, 2013 @ 09:54
    Dave Woestenborghs
    1

    Can you post the code behind of your usercontrol and some print screens of your macro definition in Umbraco

  • philw 99 posts 434 karma points
    Apr 25, 2013 @ 11:26
    philw
    101

    Ok, this was user error: it doesn't work the way it appears like it should, but it does work. Here's what I did.

    1. Create test user control as below. Copy to deployment machine.
    2. Create a macro, point it at the ascx file.
    3. Refresh/ reload, and the button "show properties" (or something like that) appears. Press it, and the property is not visible, nothing works there. Close that.
    4. Manually add a parameter, named/ Aliased "Literal1Text".
    5. Set the macro to not render in the editor (that crashes Medium Trust), but to be available there.
    6. Insert the macro into content using the Rich Text Editor. Set the parameter to something when prompted, eg "test text".
    7. The page renders on the front end when published with "test text". 
    All is good, thanks for your help with that. I was originally parsing the parameters at pre-render and perhaps that was the issue; I don't care as if this works I'll do it this way.
    <%@ Control Language="C#" ClassName="test" %>
    <script runat="server">
        /// <summary>
        /// Just bang the value into the literal.
        /// </summary>
        public String Literal1Text
        {
            set { Literal1.Text = value; }  
        }   
    </script>
    <asp:Literal runat="server" ID="Literal1" Text="this text should be replaced by the parameter" />
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 25, 2013 @ 11:30
    Dave Woestenborghs
    0

    Glad to see you have solved it.

    I usually create a code behind file for my macros. Then the browse properties box will show up with the properties

     

    Dave

  • SBS 4 posts 24 karma points
    May 17, 2013 @ 10:17
    SBS
    0

    Hi I am working User Controls.How multiple UserControl Communicate? using NodeID without Query string.

Please Sign in or register to post replies

Write your reply to:

Draft