'Image' does not contain a definition for 'ImageUrl'

J

Jeff

hi

asp.net 2.0

I get this compile error:
'Image' does not contain a definition for 'ImageUrl'

Image image = (Image)e.Item.FindControl("img");
image.ImageUrl = "~/image.png";

the compile error is on the second line above. This is strange. This used to
compile without problem. But it started after I had created a separate
folder for storing masterpages (I moved the masterpages and updated link to
them in each .aspx). Also created a new masterpage, by copying the markup of
another masterpage. Then the compile errror arrived.

any suggestions?
 
M

Mark Fitzpatrick

Probably because it is not sure which image you mean? Unless you specify the
namespace, the compiler can pull the wrong image class.

Instead try using

System.Web.UI.WebControls.Image image =
(System.Web.UI.WebControls.Image)e.Item.FindControl("img");

This ensures you're getting the correct image object.

Hope this helps,
Mark Fitzpatrick
 
J

Jeff

Firstly, are you absolutely that the first line has worked?
Yes, I've just commented out this line: image.ImageUrl = "~/image.png"; and
now it compiles
(but no image is displayed)

What does image.GetType() return?
"System.Web.UI.WebControls.Image"

what properties does IntelliSense reveal
it reveals ImageUrl

I don't think the problem is here, but somewhere else maybe. I've executed
this code many times this evening without getting that compile error. The
problem started after I've reorganized the masterpages.. well, I don't
know.. I'm confused here.

part of markup of default.aspx: MasterPageFile="~/Masters/Content.master"
and before I moved the masterpage it was: MasterPageFile="Content.master"
I don't see how that can make the problem

any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top