p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   How to load images dynamically on image control (http://p2p.wrox.com/showthread.php?t=66917)

jazzydonald March 26th, 2008 11:23 AM

How to load images dynamically on image control
 
I have an asp.net application that let user retrieve some infomation from a database and display a corresponding image stored on a folder somewhere in my pc.
The user enters a checkno and the application display records from db and an image. So far am able to get the full path of that image but i do not know how to pass that path to an image control at runtime. I didnt want to use '~\....' to specify image url at design time because my images can reside somewhere on pc or server etc. Can somebody help.


imjigu2001 March 27th, 2008 03:13 AM

hi,

you can do it at runtime like :

image1.imageurl="fullpath"

thats it.


jazzydonald March 27th, 2008 06:45 AM

Thanks imjigu2001 for the reply.
I tried that but it didnt display any image. I even tried to put the path at design time it didint work. Heres the code;

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Image1.ImageUrl = "C:\Documents and Settings\Mangulu\My Documents\coseke logo.jpeg"
End Sub





dparsons March 27th, 2008 07:28 AM

Hmm. That is a bad practice to have an image link like that. That may very well be where the image resides on your machine but it really needs to be placed in the folder where your website resides because, if you were to purchase hosting from someone, that is not where the image will reside at all.

consider this directory structure

-WebFolder
-----Images
----------coseke logo.jpeg
-----YourPage.aspx

If your image control resides on YourPage.aspx the ImageURL could be any of the following:
./Images/coseke logo.jpeg
Images/coseke logo.jpeg <--This would only work if you were actually working in a domain and not off of localhost
~/Images/coseke logo.jpeg

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========

jazzydonald March 27th, 2008 08:38 AM

Thanks dparsons for the useful infomation. I'll try to follow that practise. cheers


dparsons March 27th, 2008 08:54 AM

It is worth noting that that the tildea character (~) will only work on controls that have the attribute runat="server".

This isn't a problem in your situation since you are using an image control but this will bomb if you try to use a standard HTML img tag.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========

planoie March 27th, 2008 10:42 AM

As Doug suggests, you need to be careful where you try to use the ~ character.

Many server controls will process that character appropriately. But when you need to use a app root relative path in a non server control you can still process it manually. For example:

string correctUrl;
correctUrl = ResolveUrl("~/images/someimage.jpg");

You can now use that resolved url in plain HTML or in a control that may not process the ~ itself.

-Peter
peterlanoie.blog

jazzydonald April 2nd, 2008 06:36 AM

if my images are on the server and my application is on the same server how would i do it.(load images on my page) i.e the codes...


dparsons April 2nd, 2008 07:16 AM

I don't understand. Did my suggestions not work? What have you tried?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========

markdevid June 27th, 2016 07:14 AM

load images dynamically on image control
 
Hi guys

Here is some useful resources about how load images dynamically on image control

Check this link

https://www.mindstick.com/Articles/4...in-asp-dot-net


All times are GMT -4. The time now is 03:20 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.