I am trying to create an inline .NET macro that displays an image with a caption underneath. I created a macro with two parameters. One called CaptionText with type text and one called CaptionImage with type "mediaCurrent". I attached a .NET user control to the macro.
In the page_load method of the .NET control I want to fetch the image from the media library, but page_load is never hit. The constructor of the user control is hit, but in the constructor I don't see any values for the parameters.
Here is my macro code. I hope you can help out.
namespace Mysite.usercontrols
{
publicpartialclassImageWithCaption : System.Web.UI.UserControl
{
publicint TheImage { get; set; }
publicstring CaptionText { get; set; }
publicUmbracoImage image;
privatestaticreadonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public ImageWithCaption()
{
// At this point TheImage is 0 and CaptionText is null. Why?
Log.Debug("TheImage: " + TheImage);
Log.Debug("CaptionText: " + CaptionText);
}
protectedvoid Page_Load(object sender, EventArgs e)
{
// This is never hit
Log.Debug("TheImage in onload: " + TheImage);
Log.Debug("CaptionText in onload: " + CaptionText);
XPathNodeIterator iterator = library.GetMedia(TheImage, false);
UmbracoImage image = UmbracoFieldReader.ReadMediaImageFromIterator(iterator);
}
}
}
I found the problem myself. The problem here is that the Rich Text Editor field itself is processed by a .NET macro. This causes inline macro's to be ignored.
So, with this solution in place I thought all my inline macro's would run normally. Obviously, I was wrong. The inline .NET macro's do pass their parameters to the .NET ascx.cs file, which passes it to the ascx template. So you CAN use the parameters directly in the ascx file. You cannot however use the parameters to do aditional processing in the page_load method, because page_load is never run.
Inline macro's don't hit page_load?
Hello Umbracians,
I am trying to create an inline .NET macro that displays an image with a caption underneath. I created a macro with two parameters. One called CaptionText with type text and one called CaptionImage with type "mediaCurrent". I attached a .NET user control to the macro.
In the page_load method of the .NET control I want to fetch the image from the media library, but page_load is never hit. The constructor of the user control is hit, but in the constructor I don't see any values for the parameters.
Here is my macro code. I hope you can help out.
I found the problem myself. The problem here is that the Rich Text Editor field itself is processed by a .NET macro. This causes inline macro's to be ignored.
I solved this by stripping out all the <MACRO> declarations from the text and running them with RenderMacroContent() in the macro that processes the content of the RTE. (Look here: http://our.umbraco.org/forum/developers/api-questions/26364-Macro-content-not-showing-up-Need-workaround)
So, with this solution in place I thought all my inline macro's would run normally. Obviously, I was wrong. The inline .NET macro's do pass their parameters to the .NET ascx.cs file, which passes it to the ascx template. So you CAN use the parameters directly in the ascx file. You cannot however use the parameters to do aditional processing in the page_load method, because page_load is never run.
I used an XSLT macro instead and this works.
is working on a reply...