PC Review


Reply
Thread Tools Rate Thread

Default image in asp:image control

 
 
Paul Cheetham
Guest
Posts: n/a
 
      27th Jan 2007
Hi,

I have an application that will display user-defined images in some
asp:image controls.
(sets the ImageURL, and is always built from the site root)

The problem comes when the images specified do not exist, as it displays
a red cross and the alternate text.

What I would like to do is display a default image instead.

Does anyone know of a way to do this?
I have searched all over and the control would appear to be a little
lacking in this respect. There does not appear to be a way of
determining whether or not it has successfully loaded the image, so I
don't know when to display the default.

Unfortunately I cannot use FileExists, because I do not have a physical
path.

Any help appreciated - It's driving me mad!

Thankyou.


Paul
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      27th Jan 2007
Paul,

You can get the physical path out of virtual one with MapPath method

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"Paul Cheetham" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I have an application that will display user-defined images in some
> asp:image controls.
> (sets the ImageURL, and is always built from the site root)
>
> The problem comes when the images specified do not exist, as it displays
> a red cross and the alternate text.
>
> What I would like to do is display a default image instead.
>
> Does anyone know of a way to do this?
> I have searched all over and the control would appear to be a little
> lacking in this respect. There does not appear to be a way of
> determining whether or not it has successfully loaded the image, so I
> don't know when to display the default.
>
> Unfortunately I cannot use FileExists, because I do not have a physical
> path.
>
> Any help appreciated - It's driving me mad!
>
> Thankyou.
>
>
> Paul



 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      27th Jan 2007
Hi Paul,

The problem is related to the fact that browser is responsible for
downloading image from location specified in src attribute (as it seems you
may not know that every asp.net server control renders HTML, Image control
renders NavigateUrl as src attribute of the <img/>. It's very easy to solve
'non-existing' image problem with DOM and javascript. you can handle onerror
event as follows:


<asp:Image runat="server" ID="img" ImageUrl="nonexistingimage.gif"
onerror="DisplayDefaultImage(this)"/>
<script language="javascript">
//<!--
function DisplayDefaultImage(img)
{
img.src = 'DefaultImage.jpg';
}
//-->

Hope this heps

--
Milosz


"Paul Cheetham" wrote:

> Hi,
>
> I have an application that will display user-defined images in some
> asp:image controls.
> (sets the ImageURL, and is always built from the site root)
>
> The problem comes when the images specified do not exist, as it displays
> a red cross and the alternate text.
>
> What I would like to do is display a default image instead.
>
> Does anyone know of a way to do this?
> I have searched all over and the control would appear to be a little
> lacking in this respect. There does not appear to be a way of
> determining whether or not it has successfully loaded the image, so I
> don't know when to display the default.
>
> Unfortunately I cannot use FileExists, because I do not have a physical
> path.
>
> Any help appreciated - It's driving me mad!
>
> Thankyou.
>
>
> Paul
>

 
Reply With Quote
 
Paul Cheetham
Guest
Posts: n/a
 
      28th Jan 2007

Thanks to both of you for your help.


Paul



Paul Cheetham wrote:
> Hi,
>
> I have an application that will display user-defined images in some
> asp:image controls.
> (sets the ImageURL, and is always built from the site root)
>
> The problem comes when the images specified do not exist, as it displays
> a red cross and the alternate text.
>
> What I would like to do is display a default image instead.
>
> Does anyone know of a way to do this?
> I have searched all over and the control would appear to be a little
> lacking in this respect. There does not appear to be a way of
> determining whether or not it has successfully loaded the image, so I
> don't know when to display the default.
>
> Unfortunately I cannot use FileExists, because I do not have a physical
> path.
>
> Any help appreciated - It's driving me mad!
>
> Thankyou.
>
>
> Paul

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control image property locking image file even after image cleared steve Microsoft VB .NET 4 6th Jul 2006 02:57 AM
How to develop a program to open an image file (.jpg) with PPC's default image viewer? kyng329@hotmail.com Microsoft Dot NET Compact Framework 0 24th Mar 2006 04:16 PM
How to insert the image into the richtextbox control and catch the mouse click event of that image. Sakharam Phapale Microsoft VB .NET 1 1st Mar 2005 12:21 PM
How to insert the image into the richtextbox control and catch the mouse click event of that image. Sakharam Phapale Microsoft C# .NET 0 1st Mar 2005 10:05 AM
Changing image on Image control in Form running Access 2002 Runtime John Cosmas Microsoft Access 1 9th Feb 2004 02:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:53 AM.