473,786 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default image in asp:image control

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
Jan 27 '07 #1
3 7918
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" <PA******@dsl.p ipex.comwrote in message
news:OI******** ******@TK2MSFTN GP03.phx.gbl...
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

Jan 27 '07 #2
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="nonex istingimage.gif "
onerror="Displa yDefaultImage(t his)"/>
<script language="javas cript">
//<!--
function DisplayDefaultI mage(img)
{
img.src = 'DefaultImage.j pg';
}
//-->

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
Jan 27 '07 #3

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
Jan 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4412
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail image in a byte of what is in the database. I also want to be able to display this image in an <asp:image></asp:image> control. Is there any way to do this? Most of the examples that I've seen have used
9
1402
by: Mactash | last post by:
Folks, I have problem running simplest ASP.Net programs with IIS web server. As a test I just added some text box and dropdown list with Visual Studio but when I run this my page shows nothing.(blank page without error.) I can run this with asp matrix web server. Can you please let me know what is wrong.? Thank you .
1
1970
by: Neil Zanella | last post by:
Hello, I would like to ask a question pertaining to programmatic initialization of ASP web controls (as opposed to initialization via standalone attributes and other elements contained in the enclosing ASP control element)... Given an ASP web control that supports specifying an initialization event handler via the onInit attribute, what is the difference between placing initialization
2
1171
by: kentg | last post by:
How do I "build" the name of an ASP control in the VB Code behind? I would like to cycle through several comboboxes using a loop. (cboReport1, cboReport2, cboReport3, etc.) ie. in MS-Access I can use the following code to reference a combobox named cboReport6 and set it's value to 1: strForm = MyForm strControlName = "cboReport" intCount = 6
1
1342
by: KitKat | last post by:
With the help of kind, brilliant folks, I have been working on this program that uses a combo box selection to display six different jpgs. The jps are a time stamp, and the files are located in six different folders of camera views. HOWEVER, some of these folders do not have that certain timed jpg. So...I need to figure out how to show all the rest of the pictures and use an "no image available or something" for the program to work...
3
5604
by: Frederik Borg | last post by:
Hi I would like to use script to access an asp control client side. The asp control and script is located in a content page. I use the control's ID to call it: <button onclick="SomeOtherControl.click();">Remove</button> Unfortunately the ID of SomeOtherControl gets changed when using master pages. It owrks perfect when using regualar flat aspx pages.
1
6315
by: wkerplunk | last post by:
On mouseover it goes to the correct map say TheMap1.jpg and then on mouseOut it defaults back to map, I need to do a onClick that sets the TheMap1.jpg mouseOver to the default TheMap.jpg so the TheMap1.jpg is now the default image not the TheMap.jpg. So after I click for information, and mouseOut of that area TheMap1.jpg will stay as all the MouseOuts Until I click another area of the map say TheMap10.jpg once clicked TheMap10.jpg will become...
2
3344
by: aris1234 | last post by:
Can you use PHP to show a default image if the image field in a database row is empty? I'm creating a news page, but the client may not always upload an image with a news story. I know how to hide the area, but this leaves a big blank space. It would be much better if a default image were to appear.
12
12557
by: amandab116 | last post by:
In my program I am storing images in the database. Not all of the records in the database have images, and when I load the details into another .aspx page, sometimes the image is empty- has a red "x". How do I replace that "x" with a default image?
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.