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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

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

    hi

    asp.net 2.0

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

    Image image = (Image)e.Item.F indControl("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?


  • Mark Fitzpatrick

    #2
    Re: 'Image' does not contain a definition for 'ImageUrl'

    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.W ebControls.Imag e image =
    (System.Web.UI. WebControls.Ima ge)e.Item.FindC ontrol("img");

    This ensures you're getting the correct image object.

    Hope this helps,
    Mark Fitzpatrick

    "Jeff" <it_consultant1 @hotmail.com.NO SPAMwrote in message
    news:#jkBH1ZJJH A.1308@TK2MSFTN GP02.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.F indControl("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?
    >

    Comment

    • Mark Rae [MVP]

      #3
      Re: 'Image' does not contain a definition for 'ImageUrl'

      "Jeff" <it_consultant1 @hotmail.com.NO SPAMwrote in message
      news:%23jkBH1ZJ JHA.1308@TK2MSF TNGP02.phx.gbl. ..
      I get this compile error:
      'Image' does not contain a definition for 'ImageUrl'
      >
      Image image = (Image)e.Item.F indControl("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


      Comment

      • Jeff

        #4
        Re: 'Image' does not contain a definition for 'ImageUrl'

        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.Ima ge"

        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?


        Comment

        • Jeff

          #5
          solved

          I just applied what Mark Fitzpatrick suggested and now it works!


          Comment

          • Jeff

            #6
            thank you, you solved it

            Hi

            I applied what you suggested and it solved the problem, hurray ;)

            thanks you


            Comment

            Working...