Here is a sample I'm using to find a macro from another macro:
Control extension:
/// <summary>
/// Find a control and return it as T.
/// This controls goes recursive through all controls until the control is found.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="root"></param>
/// <param name="id"></param>
/// <returns></returns>
public static T FindControlRecursive<T>(this Control control, string controlID)
where T : Control
{
//Find the control.
Control foundControl;
if (control != null)
{
foundControl = control.FindControl(controlID);
if (foundControl != null)
{
//Return the Control as T.
return foundControl as T;
}
foreach (Control c in control.Controls)
{
foundControl = c.FindControlRecursive<T>(controlID);
if (foundControl != null)
{
//Return the Control as T.
return foundControl as T;
}
}
}
return null;
}
The code to find the macro:
//Get the header menu macro (another usercontrol) which is also on this page.
Macro menuMacro = this.Page.FindControlRecursive<Macro>("headermenuMacro");
if (menuMacro != null)
{
//Set the menu. This will be set to the selected location.
ISetMenu<int> setMenu = (ISetMenu<int>)menuMacro.Controls[0];
setMenu.SetMenu(LocationId);
}
I think you can use something like this to find the ContentPlaceHolder.
Thanks for the reply, I was hoping that I could just use the findcontrol method to grab the ContentPlaceHolder and then from the there get the control. Your approach looks good, but I'm afraid my coding is not upto this level.
Find Control in Content Place Holder
Hi All
From the masterpage page load method, I'm trying to test if it's possible to find a control in a content place holder of a general template.
The masterpage has a content place of SiteMasterContentPlaceHolder, and the test label control has an id of "test".
This returns System.NullReferenceException when attempting to locate the label control.
Thanks
Eddie
Here is a sample I'm using to find a macro from another macro:
Control extension:
The code to find the macro:
I think you can use something like this to find the ContentPlaceHolder.
Jeroen
Hi Jeroen,
Thanks for the reply, I was hoping that I could just use the findcontrol method to grab the ContentPlaceHolder and then from the there get the control. Your approach looks good, but I'm afraid my coding is not upto this level.
Eddie
Hi Jeroen,
I hope you are listening to this thread and able to help me.
I have two .Net macros on a page and within one macro I need to call a 'Refresh' method in the other.
Within my template the macro I'm trying to find looks like this:
I've created the extension method you've shown above, help here for anyone that needs it.
And I've added the following code to find the macro.
There's a couple of things I'm not sure about.
1. In Umbraco 4.7 the only macro object I could find has a lower case 'm' so am I using the right macro object?
2. Am I passing in the correct ID of the control because I've not set the ID anywhere?
Regards,
Matt
Played about with this some more and discovered the Macro object is in fact
I'm still not entirely sure what sets the ID of the control?
Anyhow, it worked fine once I started looking for the corrcet Macro object.
Hello,
When you look for a control you look for the ID of it. Normally the Macro doesn't have an ID, but it is a webcontrol so you can just set it.
For example:
You can find this with the following code:
Jeroen
Thanks Jeroen,
Got it all going.
is working on a reply...