locked
Accessing embedded images at designtime RRS feed

  • Question

  • User132352790 posted

    Anyway, I'm struggling with some designtime issues, that apparently should already have addressed, as Nikhil writes in his (not so recent) post: http://www.nikhilk.net/WebResourceAttributeAtDesignTime.aspx

    The problem however is that this doesn't work for me. I see the src property is correctly the mvwres://... and it looks fine, but I still get a broken image when I'm in designmode. However I'm not using an Image webcontrol, but render out the html using the HtmlTextWriter.
    ex:
          writer.AddAttribute(HtmlTextWriterAttribute.Src, imageUrl);
          writer.RenderBeginTag(HtmlTextWriterTag.Img);

    I have a feeling that rendering the controls like this doesn't work with embedded resources (is there logic for handling this protocol on the Image control?). Can anyone confirm that, and in that case, perhaps knows of a good workaround? (I also tried setting the src to a filepath outside the filesystem website, but it seems to be restricted to files with the website and I don't want to copy these files all over the place)

     

    Tuesday, March 25, 2008 2:14 PM

Answers

  • User132352790 posted

    Not sure why, but now it suddenly works in VS2005 as well. I'm confused (must have been a cached dll or something).

    Nevermind! 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 26, 2008 1:59 PM

All replies

  • User-125333347 posted

    The devil is in the details make sure the object is signed  and the int after mwres: is the correct index in your assembly manifest 

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Text;
    using System.Design;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Web.UI.Design.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Security;


    namespace StyleGuide
    {

        [ToolboxData("<{0}:BrandMark runat=server></{0}:BrandMark>")]
        [Designer(typeof(BrandMarkDesigner))]
        public class BrandMark : Control
        {
            // Methods
            public BrandMark() { }
        
            protected override void Render(HtmlTextWriter writer)
            {
               

                writer.Write("<img alt=\"BrandMark\" src=\"" + this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "StyleGuide.Resources.common.images.bnr_logo_75_154.gif") + "\" />");
                base.Render(writer);
            }
      }
        public class BrandMarkDesigner : ControlDesigner
        {
            public override string GetDesignTimeHtml()
            {
                return "<img alt=\"BrandMark\" src=\"mvwres:1-StyleGuide.Resources.common.images.bnr_logo_75_154.gif,StyleGuide, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9e6f94eb34ececb0\" />";
            }

     


        }
    }

     

    Tuesday, March 25, 2008 3:41 PM
  • User132352790 posted

    1. GetWebResourceUrl is automatically returning the mvwres link when in designmode, so you don't need to make all that extra special code.

    2. My assembly is signed (not that that really matters though) , and the index is correct (as stated this works at runtime).

    3. It works in VS2008, but not VS2005. Seems like a VS2005 limitation to me. I'm just looking for confirmation.

    Wednesday, March 26, 2008 12:35 PM
  • User132352790 posted

    Not sure why, but now it suddenly works in VS2005 as well. I'm confused (must have been a cached dll or something).

    Nevermind! 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 26, 2008 1:59 PM