I have a quickbasket macro (usercontrol) that has a property (int) and a method that writes this property out to a label. This works nicely on pageload.
However, when another item is added I need to call this macro from another macro (again a usercontrol), set the property and call the method to write the new figure to the page.
Traditionally I would have got a reference to this usercontrol thus:
quickbasket would then contain all the public methods and properties - however how can I achieve the same thing the umbraco way? Is there a findMacro type method?
If it's v4 then you can declare your UserControls directly on the template, therefore the above approach should still work.
If that's not the case (and maybe a better solution) you could implement a Singleton based StateManager. This class would be updated by one control and then checked by the second control.
Try and avoid controls/macros having to talk directly to each other. This generally means that they are very tightly coupled and if you change one there's a chance you may break something in another.
It is version 4, so I guess I could
just use the user controls route. I did like your idea and I agree
tightly coupling controls.
Your solution still hits on the problem I'm currently suffering, that is I need to force the usercontrol to either reload or run the update method as it will always be one step behind the current basket, if you see what I mean - it will display the basket content from the previous post.
I think maybe the solution is to just put a label directly into the master page to display it, and write a method I can call anywhere to update it - not as modular as I would like but it will work.
It depends on the position of your controls on the page along with when in the page lifecycle your updaing the labels value.
For example, if your controls are in this order:
<asp:YourLabelControl id="c1" runat="server"/>
<asp:YourSecondControl id="c2" runat="server" />
then the load method of c1 will occur before the load method of c2.
However the OnPreRender method of c1 will occur after the OnLoad method of c2. Therefore if you move the logic that sets the text of the label to the OnPreRender method then the value will have been updated by this point.
Accessing one macro from another
Hi,
I have a quickbasket macro (usercontrol) that has a property (int) and a method that writes this property out to a label. This works nicely on pageload.
However, when another item is added I need to call this macro from another macro (again a usercontrol), set the property and call the method to write the new figure to the page.
Traditionally I would have got a reference to this usercontrol thus:
usercontrols_QuickBasket quickBasket = (usercontrols_QuickBasket)Page.FindControl("QuickBasket");
quickbasket would then contain all the public methods and properties - however how can I achieve the same thing the umbraco way? Is there a findMacro type method?
Many thanks
JC
What version of Umbraco are you using?
If it's v4 then you can declare your UserControls directly on the template, therefore the above approach should still work.
If that's not the case (and maybe a better solution) you could implement a Singleton based StateManager. This class would be updated by one control and then checked by the second control.
For example, UserControl1 may have
and UserControl2 would then
Try and avoid controls/macros having to talk directly to each other. This generally means that they are very tightly coupled and if you change one there's a chance you may break something in another.
Thanks Chris,
It is version 4, so I guess I could just use the user controls route. I did like your idea and I agree tightly coupling controls.
Your solution still hits on the problem I'm currently suffering, that is I need to force the usercontrol to either reload or run the update method as it will always be one step behind the current basket, if you see what I mean - it will display the basket content from the previous post.
I think maybe the solution is to just put a label directly into the master page to display it, and write a method I can call anywhere to update it - not as modular as I would like but it will work.
Thanks for your help
JC
It depends on the position of your controls on the page along with when in the page lifecycle your updaing the labels value.
For example, if your controls are in this order:
then the load method of c1 will occur before the load method of c2.
However the OnPreRender method of c1 will occur after the OnLoad method of c2. Therefore if you move the logic that sets the text of the label to the OnPreRender method then the value will have been updated by this point.
Thanks Chris - too tired to see that one.
Working now - thanks again.
is working on a reply...