Copied to clipboard

Flag this post as spam?

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


  • leeatkinson 33 posts 44 karma points
    Jul 31, 2009 @ 11:59
    leeatkinson
    0

    HtmlImage control in Cached UserControl loses SRC attribute on subsequent requests

    Hi

    I created a UserControl that adds a HtmlImage control to it's control collection. I set it's SRC attribute and set the Cache for the macro to be 900 seconds ('Cache By Page' and 'Cache Personalized' are both off).

    On first request (e.g. when the control is first created), the SRC attribute is present. However on subsequent requests (e.g. when the control is coming from the cache), the SRC attribute is missing. Other attributes (e.g. TITLE) do exist.

    Thye code is below - as anyone come across this before? Using Umbraco 4.2.1, ASP.NET 3.5 SP1, IIS 7 on Windows 2008 Standard. Using ?umbdebugshowtrace=true all looks fine.

    Regards

    Lee

     

    The .ASCX file is:

    <%@ Control Language="C#" AutoEventWireup="false" CodeFile="ImgSrcTest.ascx.cs" Inherits="ImgSrcTest" %>

    The .ASCX.CS file is:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;


    public partial class ImgSrcTest : System.Web.UI.UserControl
    {

     protected override void OnLoad(EventArgs e)
     {
      base.OnLoad(e);
      var img = new HtmlImage();
      var imgAttributes = img.Attributes;
    imgAttributes.Add("title", "I'm here!");
      imgAttributes.Add("src", "myimage.png");
      this.Controls.Add(img);
     }
    }

    And the macro embedded into a template:

    <umbraco:Macro Alias="imageSrcTest" runat="server"></umbraco:Macro>
Please Sign in or register to post replies

Write your reply to:

Draft