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 "Jeff" <it_consultant1@hotmail.com.NOSPAM> wrote in message news:#jkBH1ZJJHA.1308@TK2MSFTNGP02.phx.gbl... > 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? >
"Jeff" <it_consultant1@hotmail.com.NOSPAM> wrote in message news:%23jkBH1ZJJHA.1308@TK2MSFTNGP02.phx.gbl... > 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? Firstly, are you absolutely that the first line has worked? What does image.GetType() return? If you set a breakpoint on the second line and then inspect the image variable in the locals window or the immediate window, what properties does IntelliSense reveal...? -- Mark Rae ASP.NET MVP http://www.markrae.net
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?
I just applied what Mark Fitzpatrick suggested and now it works!
Hi I applied what you suggested and it solved the problem, hurray ;) thanks you