Driving me nuts...

Discussion in 'ASP .Net' started by Marty, Nov 10, 2003.

  1. Marty

    Marty Guest

    It seems all of the sudden that user controls that
    contain images are referencing image sources relative to
    the document that I drop the control on. This obviously
    does not work beacuase the image source is relative to
    the user control, not necessarily the form. Can anyone
    tell me why this would be the case?
     
    Marty, Nov 10, 2003
    #1
    1. Advertising

  2. Marty

    Brian W Guest

    FWIW, this drives me nuts too!

    This is how I do it for asp image, after dropping the control on the page
    (or user control) I change the ImageUrl to something like
    "~/'images/mypicture.jpg"

    For an IMG html control I use src="<%=ResolveUrl("~/image/mypicture.jpg")%>"

    The drawback to both of these is you don't get to see the actual image in
    design mode, only the place marker.

    HTH
    Brian W





    "Marty" <> wrote in message
    news:00ae01c3a7bd$e7f13cb0$...
    > It seems all of the sudden that user controls that
    > contain images are referencing image sources relative to
    > the document that I drop the control on. This obviously
    > does not work beacuase the image source is relative to
    > the user control, not necessarily the form. Can anyone
    > tell me why this would be the case?
     
    Brian W, Nov 10, 2003
    #2
    1. Advertising

  3. Marty,

    I'm a bit confused. The URL to the image will have to be relative to the
    Webform onto which your user control is placed. If not, the image link
    will be broken.

    Jim Cheshire [MSFT]
    Developer Support
    ASP.NET


    This post is provided as-is with no warranties and confers no rights.

    --------------------
    >Content-Class: urn:content-classes:message
    >From: "Marty" <>
    >Sender: "Marty" <>
    >Subject: Driving me nuts...
    >Date: Mon, 10 Nov 2003 11:07:37 -0800
    >Lines: 6
    >Message-ID: <00ae01c3a7bd$e7f13cb0$>
    >MIME-Version: 1.0
    >Content-Type: text/plain;
    > charset="iso-8859-1"
    >Content-Transfer-Encoding: 7bit
    >X-Newsreader: Microsoft CDO for Windows 2000
    >Thread-Index: AcOnvefxXWxzEBR1RRmi3tV9aszCgw==
    >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >Path: cpmsftngxa06.phx.gbl
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:189810
    >NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >It seems all of the sudden that user controls that
    >contain images are referencing image sources relative to
    >the document that I drop the control on. This obviously
    >does not work beacuase the image source is relative to
    >the user control, not necessarily the form. Can anyone
    >tell me why this would be the case?
    >
     
    Jim Cheshire [MSFT], Nov 10, 2003
    #3
  4. Marty

    Brian W Guest

    This is exactly the problem

    When placing an image control on a UserControl the path assigned to the
    image will be relative to the user control which is not necessarily the same
    as the webform the user control is placed on.

    Take the following example:

    I have a folder/structure like this

    root \+
    Default.aspx
    +- images\
    mypicture.jpg
    +- controls
    myheader.ascx
    +- help\
    about.aspx

    if I place an image control on myheader.ascx and use the designer to assign
    the image, the designer assigns ../images/mypicture.jpg to the ImageUrl
    attribute.

    When I place myheader.ascx on Default.aspx (which reside in the root) and
    run the app the link to mypicture.jpg is broken because
    .../images/mypicture.jpg is not the correct relative path in the context of
    Default.aspx.

    Now, if I place myheader.ascx on about.aspx (residing in help directory) the
    link is un-broken because the relative path for about.aspc is correct.

    Clear as mud, right?!?! ;-)

    I actually brought this very topic up several months ago in this or the IDE
    NG.


    Brian W




    "Jim Cheshire [MSFT]" <> wrote in message
    news:...
    > Marty,
    >
    > I'm a bit confused. The URL to the image will have to be relative to the
    > Webform onto which your user control is placed. If not, the image link
    > will be broken.
    >
    > Jim Cheshire [MSFT]
    > Developer Support
    > ASP.NET
    >
    >
    > This post is provided as-is with no warranties and confers no rights.
    >
    > --------------------
    > >Content-Class: urn:content-classes:message
    > >From: "Marty" <>
    > >Sender: "Marty" <>
    > >Subject: Driving me nuts...
    > >Date: Mon, 10 Nov 2003 11:07:37 -0800
    > >Lines: 6
    > >Message-ID: <00ae01c3a7bd$e7f13cb0$>
    > >MIME-Version: 1.0
    > >Content-Type: text/plain;
    > > charset="iso-8859-1"
    > >Content-Transfer-Encoding: 7bit
    > >X-Newsreader: Microsoft CDO for Windows 2000
    > >Thread-Index: AcOnvefxXWxzEBR1RRmi3tV9aszCgw==
    > >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > >Newsgroups: microsoft.public.dotnet.framework.aspnet
    > >Path: cpmsftngxa06.phx.gbl
    > >Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet:189810
    > >NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
    > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >
    > >It seems all of the sudden that user controls that
    > >contain images are referencing image sources relative to
    > >the document that I drop the control on. This obviously
    > >does not work beacuase the image source is relative to
    > >the user control, not necessarily the form. Can anyone
    > >tell me why this would be the case?
    > >

    >
     
    Brian W, Nov 10, 2003
    #4
  5. Marty

    Marty Guest

    Thanks everyone. I've taken all the feedback and
    formulated a few scenarious which now seem to be working
    OK.

    --------------------------

    When using objects that support runat=server, use ~/ to
    indicate "virtual root":

    <a runat=server href="~/Forms/main.aspx"></a>

    When using controls that do not support runat=server
    (such as TD to set its background) use Page.ResolveURL:

    <TD background="<%=Page.ResolveUrl("~/Images/fadeBG.jpg")
    %>" height="5"></TD>

    When using javascript for control attributes:

    imgHome.Attributes.Add("onMouseOver", "this.src='" &
    Page.ResolveUrl("~/Images/btn_home_dn.gif") & "';")
     
    Marty, Nov 10, 2003
    #5
  6. Brian,

    Let me have a look into this. I'll post back to this thread ASAP.

    Jim Cheshire [MSFT]
    Developer Support
    ASP.NET


    This post is provided as-is with no warranties and confers no rights.

    --------------------
    >From: "Brian W" <brianw@gold_death_2_spam_rush.com>
    >References: <00ae01c3a7bd$e7f13cb0$>

    <>
    >Subject: Re: Driving me nuts...
    >Date: Mon, 10 Nov 2003 12:15:20 -0800
    >Lines: 89
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >Message-ID: <>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >NNTP-Posting-Host: dsl-107.goldrush.com 206.171.170.107
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
    8.phx.gbl!TK2MSFTNGP12.phx.gbl
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:189838
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >This is exactly the problem
    >
    >When placing an image control on a UserControl the path assigned to the
    >image will be relative to the user control which is not necessarily the

    same
    >as the webform the user control is placed on.
    >
    >Take the following example:
    >
    >I have a folder/structure like this
    >
    >root \+
    > Default.aspx
    > +- images\
    > mypicture.jpg
    > +- controls
    > myheader.ascx
    > +- help\
    > about.aspx
    >
    >if I place an image control on myheader.ascx and use the designer to assign
    >the image, the designer assigns ../images/mypicture.jpg to the ImageUrl
    >attribute.
    >
    >When I place myheader.ascx on Default.aspx (which reside in the root) and
    >run the app the link to mypicture.jpg is broken because
    >../images/mypicture.jpg is not the correct relative path in the context of
    >Default.aspx.
    >
    >Now, if I place myheader.ascx on about.aspx (residing in help directory)

    the
    >link is un-broken because the relative path for about.aspc is correct.
    >
    >Clear as mud, right?!?! ;-)
    >
    >I actually brought this very topic up several months ago in this or the IDE
    >NG.
    >
    >
    >Brian W
    >
    >
    >
    >
    >"Jim Cheshire [MSFT]" <> wrote in message
    >news:...
    >> Marty,
    >>
    >> I'm a bit confused. The URL to the image will have to be relative to the
    >> Webform onto which your user control is placed. If not, the image link
    >> will be broken.
    >>
    >> Jim Cheshire [MSFT]
    >> Developer Support
    >> ASP.NET
    >>
    >>
    >> This post is provided as-is with no warranties and confers no rights.
    >>
    >> --------------------
    >> >Content-Class: urn:content-classes:message
    >> >From: "Marty" <>
    >> >Sender: "Marty" <>
    >> >Subject: Driving me nuts...
    >> >Date: Mon, 10 Nov 2003 11:07:37 -0800
    >> >Lines: 6
    >> >Message-ID: <00ae01c3a7bd$e7f13cb0$>
    >> >MIME-Version: 1.0
    >> >Content-Type: text/plain;
    >> > charset="iso-8859-1"
    >> >Content-Transfer-Encoding: 7bit
    >> >X-Newsreader: Microsoft CDO for Windows 2000
    >> >Thread-Index: AcOnvefxXWxzEBR1RRmi3tV9aszCgw==
    >> >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    >> >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >> >Path: cpmsftngxa06.phx.gbl
    >> >Xref: cpmsftngxa06.phx.gbl

    >microsoft.public.dotnet.framework.aspnet:189810
    >> >NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
    >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >> >
    >> >It seems all of the sudden that user controls that
    >> >contain images are referencing image sources relative to
    >> >the document that I drop the control on. This obviously
    >> >does not work beacuase the image source is relative to
    >> >the user control, not necessarily the form. Can anyone
    >> >tell me why this would be the case?
    >> >

    >>

    >
    >
    >
     
    Jim Cheshire [MSFT], Nov 10, 2003
    #6
  7. Marty

    Brian W Guest

    For reference, see this thread started December of last year in this very NG

    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OXBB3MEsCHA.1656@TK2MSFTNGP09


    Brian W


    "Jim Cheshire [MSFT]" <> wrote in message
    news:SICPSB%...
    > Brian,
    >
    > Let me have a look into this. I'll post back to this thread ASAP.
    >
    > Jim Cheshire [MSFT]
    > Developer Support
    > ASP.NET
    >
    >
    > This post is provided as-is with no warranties and confers no rights.
    >
    > --------------------
    > >From: "Brian W" <brianw@gold_death_2_spam_rush.com>
    > >References: <00ae01c3a7bd$e7f13cb0$>

    > <>
    > >Subject: Re: Driving me nuts...
    > >Date: Mon, 10 Nov 2003 12:15:20 -0800
    > >Lines: 89
    > >X-Priority: 3
    > >X-MSMail-Priority: Normal
    > >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > >Message-ID: <>
    > >Newsgroups: microsoft.public.dotnet.framework.aspnet
    > >NNTP-Posting-Host: dsl-107.goldrush.com 206.171.170.107
    > >Path:

    >

    cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
    > 8.phx.gbl!TK2MSFTNGP12.phx.gbl
    > >Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet:189838
    > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >
    > >This is exactly the problem
    > >
    > >When placing an image control on a UserControl the path assigned to the
    > >image will be relative to the user control which is not necessarily the

    > same
    > >as the webform the user control is placed on.
    > >
    > >Take the following example:
    > >
    > >I have a folder/structure like this
    > >
    > >root \+
    > > Default.aspx
    > > +- images\
    > > mypicture.jpg
    > > +- controls
    > > myheader.ascx
    > > +- help\
    > > about.aspx
    > >
    > >if I place an image control on myheader.ascx and use the designer to

    assign
    > >the image, the designer assigns ../images/mypicture.jpg to the ImageUrl
    > >attribute.
    > >
    > >When I place myheader.ascx on Default.aspx (which reside in the root) and
    > >run the app the link to mypicture.jpg is broken because
    > >../images/mypicture.jpg is not the correct relative path in the context

    of
    > >Default.aspx.
    > >
    > >Now, if I place myheader.ascx on about.aspx (residing in help directory)

    > the
    > >link is un-broken because the relative path for about.aspc is correct.
    > >
    > >Clear as mud, right?!?! ;-)
    > >
    > >I actually brought this very topic up several months ago in this or the

    IDE
    > >NG.
    > >
    > >
    > >Brian W
    > >
    > >
    > >
    > >
    > >"Jim Cheshire [MSFT]" <> wrote in message
    > >news:...
    > >> Marty,
    > >>
    > >> I'm a bit confused. The URL to the image will have to be relative to

    the
    > >> Webform onto which your user control is placed. If not, the image link
    > >> will be broken.
    > >>
    > >> Jim Cheshire [MSFT]
    > >> Developer Support
    > >> ASP.NET
    > >>
    > >>
    > >> This post is provided as-is with no warranties and confers no rights.
    > >>
    > >> --------------------
    > >> >Content-Class: urn:content-classes:message
    > >> >From: "Marty" <>
    > >> >Sender: "Marty" <>
    > >> >Subject: Driving me nuts...
    > >> >Date: Mon, 10 Nov 2003 11:07:37 -0800
    > >> >Lines: 6
    > >> >Message-ID: <00ae01c3a7bd$e7f13cb0$>
    > >> >MIME-Version: 1.0
    > >> >Content-Type: text/plain;
    > >> > charset="iso-8859-1"
    > >> >Content-Transfer-Encoding: 7bit
    > >> >X-Newsreader: Microsoft CDO for Windows 2000
    > >> >Thread-Index: AcOnvefxXWxzEBR1RRmi3tV9aszCgw==
    > >> >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > >> >Newsgroups: microsoft.public.dotnet.framework.aspnet
    > >> >Path: cpmsftngxa06.phx.gbl
    > >> >Xref: cpmsftngxa06.phx.gbl

    > >microsoft.public.dotnet.framework.aspnet:189810
    > >> >NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
    > >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >> >
    > >> >It seems all of the sudden that user controls that
    > >> >contain images are referencing image sources relative to
    > >> >the document that I drop the control on. This obviously
    > >> >does not work beacuase the image source is relative to
    > >> >the user control, not necessarily the form. Can anyone
    > >> >tell me why this would be the case?
    > >> >
    > >>

    > >
    > >
    > >

    >
     
    Brian W, Nov 10, 2003
    #7
  8. I tested this on VS.NET 2002 and the 1.0 and 1.1 Framework and could not
    reproduce it. I then tested the same thing on VS.NET 2003 and again could
    not reproduce it.

    I created a new user control and added an Image control to it. I then set
    the image src and it is relative to the user control (which is what I would
    expect since the dialog is set to Document Relative.) I then add my user
    control to a webform in another folder (so that the relative path will be
    different) and then build and browse. The image link is corrected to be
    relative to the page.

    Can someone encountering this problem provide me with some repro steps?

    Jim Cheshire [MSFT]
    Developer Support
    ASP.NET


    This post is provided as-is with no warranties and confers no rights.

    --------------------
    >From: "Brian W" <brianw@gold_death_2_spam_rush.com>
    >References: <00ae01c3a7bd$e7f13cb0$>

    <>
    <>
    <SICPSB#>
    >Subject: Re: Driving me nuts...
    >Date: Mon, 10 Nov 2003 15:41:24 -0800
    >Lines: 142
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >Message-ID: <#8XRtQ#>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >NNTP-Posting-Host: dsl-107.goldrush.com 206.171.170.107
    >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:189892
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >For reference, see this thread started December of last year in this very

    NG
    >
    >http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OXBB3MEsCH

    A.1656%40TK2MSFTNGP09
    >
    >
    >Brian W
    >
    >
    >"Jim Cheshire [MSFT]" <> wrote in message
    >news:SICPSB%...
    >> Brian,
    >>
    >> Let me have a look into this. I'll post back to this thread ASAP.
    >>
    >> Jim Cheshire [MSFT]
    >> Developer Support
    >> ASP.NET
    >>
    >>
    >> This post is provided as-is with no warranties and confers no rights.
    >>
    >> --------------------
    >> >From: "Brian W" <brianw@gold_death_2_spam_rush.com>
    >> >References: <00ae01c3a7bd$e7f13cb0$>

    >> <>
    >> >Subject: Re: Driving me nuts...
    >> >Date: Mon, 10 Nov 2003 12:15:20 -0800
    >> >Lines: 89
    >> >X-Priority: 3
    >> >X-MSMail-Priority: Normal
    >> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >> >Message-ID: <>
    >> >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >> >NNTP-Posting-Host: dsl-107.goldrush.com 206.171.170.107
    >> >Path:

    >>

    >cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP

    0
    >> 8.phx.gbl!TK2MSFTNGP12.phx.gbl
    >> >Xref: cpmsftngxa06.phx.gbl

    >microsoft.public.dotnet.framework.aspnet:189838
    >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >> >
    >> >This is exactly the problem
    >> >
    >> >When placing an image control on a UserControl the path assigned to the
    >> >image will be relative to the user control which is not necessarily the

    >> same
    >> >as the webform the user control is placed on.
    >> >
    >> >Take the following example:
    >> >
    >> >I have a folder/structure like this
    >> >
    >> >root \+
    >> > Default.aspx
    >> > +- images\
    >> > mypicture.jpg
    >> > +- controls
    >> > myheader.ascx
    >> > +- help\
    >> > about.aspx
    >> >
    >> >if I place an image control on myheader.ascx and use the designer to

    >assign
    >> >the image, the designer assigns ../images/mypicture.jpg to the ImageUrl
    >> >attribute.
    >> >
    >> >When I place myheader.ascx on Default.aspx (which reside in the root)

    and
    >> >run the app the link to mypicture.jpg is broken because
    >> >../images/mypicture.jpg is not the correct relative path in the context

    >of
    >> >Default.aspx.
    >> >
    >> >Now, if I place myheader.ascx on about.aspx (residing in help directory)

    >> the
    >> >link is un-broken because the relative path for about.aspc is correct.
    >> >
    >> >Clear as mud, right?!?! ;-)
    >> >
    >> >I actually brought this very topic up several months ago in this or the

    >IDE
    >> >NG.
    >> >
    >> >
    >> >Brian W
    >> >
    >> >
    >> >
    >> >
    >> >"Jim Cheshire [MSFT]" <> wrote in message
    >> >news:...
    >> >> Marty,
    >> >>
    >> >> I'm a bit confused. The URL to the image will have to be relative to

    >the
    >> >> Webform onto which your user control is placed. If not, the image

    link
    >> >> will be broken.
    >> >>
    >> >> Jim Cheshire [MSFT]
    >> >> Developer Support
    >> >> ASP.NET
    >> >>
    >> >>
    >> >> This post is provided as-is with no warranties and confers no rights.
    >> >>
    >> >> --------------------
    >> >> >Content-Class: urn:content-classes:message
    >> >> >From: "Marty" <>
    >> >> >Sender: "Marty" <>
    >> >> >Subject: Driving me nuts...
    >> >> >Date: Mon, 10 Nov 2003 11:07:37 -0800
    >> >> >Lines: 6
    >> >> >Message-ID: <00ae01c3a7bd$e7f13cb0$>
    >> >> >MIME-Version: 1.0
    >> >> >Content-Type: text/plain;
    >> >> > charset="iso-8859-1"
    >> >> >Content-Transfer-Encoding: 7bit
    >> >> >X-Newsreader: Microsoft CDO for Windows 2000
    >> >> >Thread-Index: AcOnvefxXWxzEBR1RRmi3tV9aszCgw==
    >> >> >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    >> >> >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >> >> >Path: cpmsftngxa06.phx.gbl
    >> >> >Xref: cpmsftngxa06.phx.gbl
    >> >microsoft.public.dotnet.framework.aspnet:189810
    >> >> >NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
    >> >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >> >> >
    >> >> >It seems all of the sudden that user controls that
    >> >> >contain images are referencing image sources relative to
    >> >> >the document that I drop the control on. This obviously
    >> >> >does not work beacuase the image source is relative to
    >> >> >the user control, not necessarily the form. Can anyone
    >> >> >tell me why this would be the case?
    >> >> >
    >> >>
    >> >
    >> >
    >> >

    >>

    >
    >
    >
     
    Jim Cheshire [MSFT], Nov 11, 2003
    #8
  9. Marty

    Marty Guest

    Hello Jim,

    I've created several user controls with no problem, but
    only recently have I included images in them, resulting
    in the problem I identified. My app structure is the
    following:

    <bin>
    <images>
    <forms>
    legal.aspx
    ...
    <usercontrols>
    main.aspx

    When I place a user control in a same level directory as
    the <usercontrols> directory (such as a form in the
    <forms> directory all is fine. But when I place a user
    control in the main.aspx page, which is in the root, the
    images in the user control are not resolved.

    This is not really a big deal, but it would sure be nice
    to be able to see the images used in the user control in
    the designer. As it is now, I had to use the methods I
    described in my last post, resulting in empty image
    placeholders from the designer. Like I said, it's not a
    big deal. Maybe I'm doing something wrong, but I've also
    seen other posts from individuals who had to resort to
    what I did to make this work. One would think, though,
    that the image sources in a user control would correct
    themselves when they are placed on a form.
     
    Marty, Nov 12, 2003
    #9
  10. Marty

    Mark Guest

    Annoying, yes. You didn't reply to the same thread, so I can't see the
    previous discussion, but the solution to this problem is to use absolute URL
    paths for all your images. For example ...
    imgsrc="http://yourdotcom.com/images/myimageisprettierthanyours.jpg"

    NOW - I'd love to find a solution to the problem of having multiple projects
    .... and having to create multiple copies of the user control so you have one
    in each project. Wouldn't it be slick if you could share user controls
    across projects without having to create a custom control in a .dll?

    mark

    "Marty" <> wrote in message
    news:07e101c3a942$7c9f5ba0$...
    > Hello Jim,
    >
    > I've created several user controls with no problem, but
    > only recently have I included images in them, resulting
    > in the problem I identified. My app structure is the
    > following:
    >
    > <bin>
    > <images>
    > <forms>
    > legal.aspx
    > ...
    > <usercontrols>
    > main.aspx
    >
    > When I place a user control in a same level directory as
    > the <usercontrols> directory (such as a form in the
    > <forms> directory all is fine. But when I place a user
    > control in the main.aspx page, which is in the root, the
    > images in the user control are not resolved.
    >
    > This is not really a big deal, but it would sure be nice
    > to be able to see the images used in the user control in
    > the designer. As it is now, I had to use the methods I
    > described in my last post, resulting in empty image
    > placeholders from the designer. Like I said, it's not a
    > big deal. Maybe I'm doing something wrong, but I've also
    > seen other posts from individuals who had to resort to
    > what I did to make this work. One would think, though,
    > that the image sources in a user control would correct
    > themselves when they are placed on a form.
     
    Mark, Nov 12, 2003
    #10
  11. Marty

    Brian W Guest

    "Mark" <> wrote in message
    news:...
    > Annoying, yes. You didn't reply to the same thread, so


    Actually, Marty did reply to the same thread.


    > previous discussion, but the solution to this problem is to use absolute

    URL
    > paths for all your images. For example ...
    > imgsrc="http://yourdotcom.com/images/myimageisprettierthanyours.jpg"


    Which prevents you from developing on one machine and later copying to a
    server (testing or production) with a different path.

    In many situations, copying anything to production before it is "released"
    is forbidden by policy.

    And the solution is as follows:

    Use <asp:Image> control and use a relative path (relative to the user
    control). For example if your user controls are in a subdirectory called
    "Controls" and your images are in "Images" you would do something like the
    following:

    <asp:image id="img1" runat="server"
    imageurl="../images/myimage.jpg"></asp:image>

    No matter where the user control is in relation to the document it is placed
    on the image will not be broken.

    This works with <asp:hyperlink> control too.

    This does not work if you use <img> or <a> tags, on your user controls.

    If you are using the Property browser use the images selector, make sure
    t6he URL Type is set to "Document Relative"


    HTH

    Regards
    Brian W


    >
    > NOW - I'd love to find a solution to the problem of having multiple

    projects
    > ... and having to create multiple copies of the user control so you have

    one
    > in each project. Wouldn't it be slick if you could share user controls
    > across projects without having to create a custom control in a .dll?
    >
    > mark
    >
    > "Marty" <> wrote in message
    > news:07e101c3a942$7c9f5ba0$...
    > > Hello Jim,
    > >
    > > I've created several user controls with no problem, but
    > > only recently have I included images in them, resulting
    > > in the problem I identified. My app structure is the
    > > following:
    > >
    > > <bin>
    > > <images>
    > > <forms>
    > > legal.aspx
    > > ...
    > > <usercontrols>
    > > main.aspx
    > >
    > > When I place a user control in a same level directory as
    > > the <usercontrols> directory (such as a form in the
    > > <forms> directory all is fine. But when I place a user
    > > control in the main.aspx page, which is in the root, the
    > > images in the user control are not resolved.
    > >
    > > This is not really a big deal, but it would sure be nice
    > > to be able to see the images used in the user control in
    > > the designer. As it is now, I had to use the methods I
    > > described in my last post, resulting in empty image
    > > placeholders from the designer. Like I said, it's not a
    > > big deal. Maybe I'm doing something wrong, but I've also
    > > seen other posts from individuals who had to resort to
    > > what I did to make this work. One would think, though,
    > > that the image sources in a user control would correct
    > > themselves when they are placed on a form.

    >
    >
     
    Brian W, Nov 12, 2003
    #11
  12. Marty

    Brian W Guest

    Jim,

    Thanks for your time.

    I can no longer confirm this on VS.NET 2002. (I don't have it installed any
    longer)

    I know this behavior is present in VS.NET 2003 present if you are using an
    HTML <img> tag, but, that's kind of expected.

    I would be interested in performance differences between the 2 following
    lines of code:

    <img src='<%=ResolveUrl("~/images/mypicture.jpg")%>'

    <asp:image id="img1" runat="server"
    imageurl="~/images/mypicture.jpg"></asp:image>


    Regards
    Brian W

    "Jim Cheshire [MSFT]" <> wrote in message
    news:...
    > I tested this on VS.NET 2002 and the 1.0 and 1.1 Framework and could not
    > reproduce it. I then tested the same thing on VS.NET 2003 and again could
    > not reproduce it.
    >
    > I created a new user control and added an Image control to it. I then set
    > the image src and it is relative to the user control (which is what I

    would
    > expect since the dialog is set to Document Relative.) I then add my user
    > control to a webform in another folder (so that the relative path will be
    > different) and then build and browse. The image link is corrected to be
    > relative to the page.
    >
    > Can someone encountering this problem provide me with some repro steps?
    >
    > Jim Cheshire [MSFT]
    > Developer Support
    > ASP.NET
    >
    >
    > This post is provided as-is with no warranties and confers no rights.
    >
    > --------------------
    > >From: "Brian W" <brianw@gold_death_2_spam_rush.com>
    > >References: <00ae01c3a7bd$e7f13cb0$>

    > <>
    > <>
    > <SICPSB#>
    > >Subject: Re: Driving me nuts...
    > >Date: Mon, 10 Nov 2003 15:41:24 -0800
    > >Lines: 142
    > >X-Priority: 3
    > >X-MSMail-Priority: Normal
    > >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > >Message-ID: <#8XRtQ#>
    > >Newsgroups: microsoft.public.dotnet.framework.aspnet
    > >NNTP-Posting-Host: dsl-107.goldrush.com 206.171.170.107
    > >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
    > >Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet:189892
    > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >
    > >For reference, see this thread started December of last year in this very

    > NG
    > >

    >
    >http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OXBB3MEsCH
    > A.1656%40TK2MSFTNGP09
    > >
    > >
    > >Brian W
    > >
    > >
    > >"Jim Cheshire [MSFT]" <> wrote in message
    > >news:SICPSB%...
    > >> Brian,
    > >>
    > >> Let me have a look into this. I'll post back to this thread ASAP.
    > >>
    > >> Jim Cheshire [MSFT]
    > >> Developer Support
    > >> ASP.NET
    > >>
    > >>
    > >> This post is provided as-is with no warranties and confers no rights.
    > >>
    > >> --------------------
    > >> >From: "Brian W" <brianw@gold_death_2_spam_rush.com>
    > >> >References: <00ae01c3a7bd$e7f13cb0$>
    > >> <>
    > >> >Subject: Re: Driving me nuts...
    > >> >Date: Mon, 10 Nov 2003 12:15:20 -0800
    > >> >Lines: 89
    > >> >X-Priority: 3
    > >> >X-MSMail-Priority: Normal
    > >> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > >> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > >> >Message-ID: <>
    > >> >Newsgroups: microsoft.public.dotnet.framework.aspnet
    > >> >NNTP-Posting-Host: dsl-107.goldrush.com 206.171.170.107
    > >> >Path:
    > >>

    >
    >cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP
    > 0
    > >> 8.phx.gbl!TK2MSFTNGP12.phx.gbl
    > >> >Xref: cpmsftngxa06.phx.gbl

    > >microsoft.public.dotnet.framework.aspnet:189838
    > >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >> >
    > >> >This is exactly the problem
    > >> >
    > >> >When placing an image control on a UserControl the path assigned to

    the
    > >> >image will be relative to the user control which is not necessarily

    the
    > >> same
    > >> >as the webform the user control is placed on.
    > >> >
    > >> >Take the following example:
    > >> >
    > >> >I have a folder/structure like this
    > >> >
    > >> >root \+
    > >> > Default.aspx
    > >> > +- images\
    > >> > mypicture.jpg
    > >> > +- controls
    > >> > myheader.ascx
    > >> > +- help\
    > >> > about.aspx
    > >> >
    > >> >if I place an image control on myheader.ascx and use the designer to

    > >assign
    > >> >the image, the designer assigns ../images/mypicture.jpg to the

    ImageUrl
    > >> >attribute.
    > >> >
    > >> >When I place myheader.ascx on Default.aspx (which reside in the root)

    > and
    > >> >run the app the link to mypicture.jpg is broken because
    > >> >../images/mypicture.jpg is not the correct relative path in the

    context
    > >of
    > >> >Default.aspx.
    > >> >
    > >> >Now, if I place myheader.ascx on about.aspx (residing in help

    directory)
    > >> the
    > >> >link is un-broken because the relative path for about.aspc is correct.
    > >> >
    > >> >Clear as mud, right?!?! ;-)
    > >> >
    > >> >I actually brought this very topic up several months ago in this or

    the
    > >IDE
    > >> >NG.
    > >> >
    > >> >
    > >> >Brian W
    > >> >
    > >> >
    > >> >
    > >> >
    > >> >"Jim Cheshire [MSFT]" <> wrote in message
    > >> >news:...
    > >> >> Marty,
    > >> >>
    > >> >> I'm a bit confused. The URL to the image will have to be relative

    to
    > >the
    > >> >> Webform onto which your user control is placed. If not, the image

    > link
    > >> >> will be broken.
    > >> >>
    > >> >> Jim Cheshire [MSFT]
    > >> >> Developer Support
    > >> >> ASP.NET
    > >> >>
    > >> >>
    > >> >> This post is provided as-is with no warranties and confers no

    rights.
    > >> >>
    > >> >> --------------------
    > >> >> >Content-Class: urn:content-classes:message
    > >> >> >From: "Marty" <>
    > >> >> >Sender: "Marty" <>
    > >> >> >Subject: Driving me nuts...
    > >> >> >Date: Mon, 10 Nov 2003 11:07:37 -0800
    > >> >> >Lines: 6
    > >> >> >Message-ID: <00ae01c3a7bd$e7f13cb0$>
    > >> >> >MIME-Version: 1.0
    > >> >> >Content-Type: text/plain;
    > >> >> > charset="iso-8859-1"
    > >> >> >Content-Transfer-Encoding: 7bit
    > >> >> >X-Newsreader: Microsoft CDO for Windows 2000
    > >> >> >Thread-Index: AcOnvefxXWxzEBR1RRmi3tV9aszCgw==
    > >> >> >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > >> >> >Newsgroups: microsoft.public.dotnet.framework.aspnet
    > >> >> >Path: cpmsftngxa06.phx.gbl
    > >> >> >Xref: cpmsftngxa06.phx.gbl
    > >> >microsoft.public.dotnet.framework.aspnet:189810
    > >> >> >NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
    > >> >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >> >> >
    > >> >> >It seems all of the sudden that user controls that
    > >> >> >contain images are referencing image sources relative to
    > >> >> >the document that I drop the control on. This obviously
    > >> >> >does not work beacuase the image source is relative to
    > >> >> >the user control, not necessarily the form. Can anyone
    > >> >> >tell me why this would be the case?
    > >> >> >
    > >> >>
    > >> >
    > >> >
    > >> >
    > >>

    > >
    > >
    > >

    >
     
    Brian W, Nov 12, 2003
    #12
  13. Marty

    Guest Guest

    I hear you Mark.

    All I can say is that I have confidense in Microsoft, in
    that some of these issues might be resolved in a future
    release of dotnet. What troubles me, and this might be
    better suited for a different thread, is that we have to
    firstly experience all of these quirks (however much time
    this takes), and then find a 'work-around' for each. I
    guess this is inherent with any application. For
    instance, when will the day come when we can load VS.Net,
    and maybe ComponentOne components, and call it a day?
    We're almost there with VS, but I still use Dreamweaver,
    Photoshop, and good 'ol TextPad to drill down to levels
    that VS isn't so good with. Like I said...I have
    confidense in Microsoft.
     
    Guest, Nov 12, 2003
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bob

    format driving me nuts

    bob, Jul 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    398
  2. Simple Simon

    DateTime driving me nuts

    Simple Simon, Jul 29, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    374
    Simple Simon
    Jul 29, 2003
  3. Bjoern Wolfgardt

    Impersonate and IIS6 driving me nuts

    Bjoern Wolfgardt, Jan 15, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,138
    bruce barker
    Jan 16, 2004
  4. Simon Harris

    XMLDocument - Driving me nuts!!

    Simon Harris, May 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    326
    Simon Harris
    May 11, 2005
  5. Simon Harris

    XMLDocument - Driving me nuts!!

    Simon Harris, May 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    315
    Simon Harris
    May 11, 2005
Loading...

Share This Page