Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • julius 107 posts 289 karma points
    Dec 25, 2011 @ 15:41
    julius
    0

    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.

     

    namespace Mysite.usercontrols
    {
        public partial class ImageWithCaption : System.Web.UI.UserControl
        {
            public int TheImage { getset; }
            public string CaptionText { getset; }
            public UmbracoImage image;
    
            private static readonly 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);
            }
    
            protected void 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);
            }
        }
    }
  • julius 107 posts 289 karma points
    Dec 29, 2011 @ 13:43
    julius
    0

    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.

     

Please Sign in or register to post replies

Write your reply to:

Draft