locked
Display HTML Image in Web Custom Control from Resource file RRS feed

  • Question

  • Hello,
    I'm trying to create Web Custom Control.
    The purpose of this control is to display company banner on the top of the page.
    The banner it self is Image file( it could be Bitmap, Jpeg or other format).
    I'm trying to store this Image in Resource file and when I build "Child Controls" on this Web Custom Control, I want to set HtmlImage to display stored image from Resource file.
    Right now, I'm having problem to do so.
    If you have any suggestions, please let me know.
    Thanks in advance!
    • Moved by Guo Surfer Tuesday, April 7, 2009 2:25 AM About ASP.NET question
    Monday, March 30, 2009 7:28 PM

Answers

  • You can make your custom control contain an <img tag that calls another page.  I generally stick this type of .aspx page into my images folder as that is it's purpose - to display an image.  Then in the aspx page you can put the code that looks up the resource and displays it appropriately.  Hope this nails it for you!
    Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net
    • Marked as answer by aaishinsky Thursday, May 28, 2009 1:20 PM
    Thursday, April 16, 2009 1:23 AM

All replies

  • Why don't you use an PictureBox? I think it's easier and more practic to load an image.
    Monday, March 30, 2009 8:04 PM
  • Take a look at this article to fully understand the image being stored in resource files.  It also shows how to get the image out of the resource file as a bitmap. 

    http://msdn.microsoft.com/en-us/library/7k989cfy.aspx

    This bitmap could then be streamed out to an <img... tag.  Put some code like this in your aspx file and then call the aspx page as the src of your image tag in your page.

    Response.Clear();
    Response.ContentType = {the mime type of your image...jpg, gif, etc.};
    Response.BinaryWrite({binary form of your bitmap}.ToArray());
    Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net
    • Proposed as answer by Andrew Siemer Thursday, April 16, 2009 1:24 AM
    Monday, March 30, 2009 8:10 PM
  • I understand how to get BItmap from Resorce file. I have a problem to assign this bitmap to HtmlImage dynamically.
    Thanks!
    Tuesday, March 31, 2009 7:42 PM
  • Put this code into an aspx page and then place the url to this page in an image control or an img tag.

    Response.Clear();
    Response.ContentType = {the mime type of your image...jpg, gif, etc.};
    Response.BinaryWrite({binary form of your bitmap}.ToArray());

    This code will stream the contents of your image from the database (or object) out to your calling page or control.
    Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net
    • Proposed as answer by Andrew Siemer Wednesday, April 1, 2009 9:56 PM
    • Marked as answer by Guo Surfer Friday, April 3, 2009 6:27 AM
    • Unmarked as answer by Guo Surfer Friday, April 3, 2009 6:28 AM
    • Unproposed as answer by Guo Surfer Tuesday, April 7, 2009 2:23 AM
    Wednesday, April 1, 2009 9:55 PM
  • Hi aaishinsky,

    Have you resolved your issue?
    If you still have problem, please consider posting your thread to http://forums.asp.net/. You may get quicker and better responses there.
    Thank you!

    Best regards,
    Guo


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 3, 2009 6:34 AM
  • Hi Andrew,
    thanks for response!
    I still having problems, because I'm working with Web Custom Control and there no aspx pages available in it.
    I have to assign url to the image inside of the Custom Control so when I will drop this control from toolbox to aspx page, image will be already there.

    Thanks again!

    Friday, April 3, 2009 1:24 PM
  • Guo hello,
    thank you, I will definitely try.
    Friday, April 3, 2009 1:27 PM
  • You can make your custom control contain an <img tag that calls another page.  I generally stick this type of .aspx page into my images folder as that is it's purpose - to display an image.  Then in the aspx page you can put the code that looks up the resource and displays it appropriately.  Hope this nails it for you!
    Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net
    • Marked as answer by aaishinsky Thursday, May 28, 2009 1:20 PM
    Thursday, April 16, 2009 1:23 AM
  • Thank You Andrew.
    Thursday, May 28, 2009 1:20 PM