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

  • Thread starter Thread starter Jeff
  • Start date Start date
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?
 
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
 
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?
 
Back
Top