Display image from codebehind (page_load) event RRS feed

  • Question

  • User1183532158 posted

    Hi Everyone -

    I have a gif image saved in the resource file,

    i can access the image by doing this....

    imgLogo = (Image)this.GetGlobalResourceObject("AppName", "banner5.gif");

    Now i need to display that graphic on my page...

    what control do i use??

    I've tried the asp:img control, but its is looking for a URL...

     any ideas??




    p.s.  vs2k5

    Monday, October 30, 2006 2:55 PM


  • User300685930 posted

    there is probably an easier way, but I created a custom httphandler and display it from that.  Here is my code:

    /// <summary>
        /// referenced from web.config for displaying an image
        /// </summary>
        public class CaptchaTypeHandler : IHttpHandler
            public void ProcessRequest(HttpContext context)
                if (context.Request.QueryString["encryptedvalue"] == null)
                    // likely, this is in design mode and we want to just show the
                    // default image for type 2.
                    Assembly assembly = Assembly.GetExecutingAssembly();
                    Stream imgStream =
                    byte[] ba = new byte[imgStream.Length];
                    imgStream.Read(ba, 0, Convert.ToInt32(imgStream.Length));

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 30, 2006 8:15 PM