Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hellow Everyone,

This is Sohaib Ameen here and I am working as a software engineer in lahore pakistan on various projects. I have some images in one of My folder "Layouts" and I am building Dashboard application in which I am getting DIV IDS at runtime from database. On the basis of the Id suppose DIV Id="1" then I have to get image from folder having name "1.png". Can Anyone suggest me a way that how can I get the static Image dynamically on div ID base?
Posted
Comments
Prasad Khandekar 25-Mar-13 8:30am    
Hello Sohaib,

This can be done in two ways. The first way is to have the image folder inside your application root so that client can reference these images using a relative path (e.g. if your appliocation root is fooapp and image folder name is images located just under fooapp then a image can be referenced using a simple relative path images/1.png. It's not very hard to put this logic in code behind all you have to do is a add a image control and set the ImageUrl property to above mentioned path. Obiviously the image name will change as per the div name).

The other way is used when image folder is located outside of the application root, It's done via HTTPhandlers. HTTP handler is a .NET components that implement the System.Web.IHttpHandler interface. It can act as a target for the incoming HTTP requests and can be called directly by using it's file name in the URL. HTTP handlers implement the following two methods:

1) ProcessRequest - Called to process http requests and
2) IsReusable - Which indicates whether this instance of http handler can be reused for fulfilling another requests of the same type.

A nice tutorial on this can be found here (http://www.c-sharpcorner.com/UploadFile/desaijm/HTTPHandlersForImages11152005062705AM/HTTPHandlersForImages.aspx).

Regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900