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.
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.
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.
Create test user control as below. Copy to deployment machine.
Create a macro, point it at the ascx file.
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.
Manually add a parameter, named/ Aliased "Literal1Text".
Set the macro to not render in the editor (that crashes Medium Trust), but to be available there.
Insert the macro into content using the Rich Text Editor. Set the parameter to something when prompted, eg "test text".
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" />
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.
For using usercontrol macros with parameters you will do this.
You create a user control with public properties e.g.
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
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:
Can you post the code behind of your usercontrol and some print screens of your macro definition in Umbraco
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.
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
Hi I am working User Controls.How multiple UserControl Communicate? using NodeID without Query string.
is working on a reply...