Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 728
  • Last Modified:

alternate image in imagefield

Hi experty type ppl,

If an image doesn't exist I'd like to replace it with a default image. The following is the code I have.

<asp:ImageField DataImageUrlFormatString="~/PhotoDisplay.ashx?photoid={0}&amp;size=small"
DataImageUrlField="PreviewImageId" SortExpression="PreviewImageId" AlternateText="No Photo.">
      <ItemStyle CssClass="col_photo" />
      <HeaderStyle CssClass="col_photo" />
</asp:ImageField>
0
Netlink2
Asked:
Netlink2
  • 2
1 Solution
 
McExpCommented:
The subsititution of the defualt image would best be done in your handler.

Purists would also say that Alternate Text should describe the image (for text readers) not be used in the absence of a valid image.
0
 
McExpCommented:
I'm assuming that at some point in your Handler you load the image into an in memory representation, if so you could do something like this: -

string file = "filenameofimagetoload"

Image oImg = null;

        try
        {
            oImg = Image.FromFile(file);
        }
        catch
        {
            oImg = Image.FromFile(HttpContext.Current.Server.MapPath("~/images/ErrorImage.jpg"));
        }
0
 
Netlink2Author Commented:
I ended up using codebehind with vb to see if the file exists. Your suggestion pointed me in the right direction.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now