UserControls in a different directory

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Sep 24, 2006.

  1. I have my UserControls in a subdirectory called usercontrols. In the code
    for one of my UserControls I have the following:

    Public Property adimage() As String
    Get
    Return lnkAdvertisement.ImageUrl
    End Get
    Set(ByVal value As String)
    Response.Write(Me.Page.ResolveClientUrl(value) & "<br/>" &
    ControlChars.NewLine)
    lnkAdvertisement.ImageUrl = Me.Page.ResolveClientUrl(value)
    System.Diagnostics.Debug.Write(Me.Page.ResolveClientUrl(value))
    End Set
    End Property


    In the Page that uses this UserControl I pass it the value
    "images/bannerad.jpg". However, when I open the page, the Response.Write()
    and Debug.Write() lines both output 'images/bannerad.jpg' but the value that
    gets assigned to lnkAdvertisement.ImageUrl is
    'usercontrols/images/bannerad.jpg'. Why is a different value being returned
    by Me.Page.ResolveClientUrl(value)? My main goal is to make the paths I pass
    when using the UserControl to be treated as relative to the path of the Page
    containing the UserControl, not the path of the UserControl. What should I
    do? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Sep 24, 2006
    #1
    1. Advertising

  2. Is there a way to get the directory that the Page using the control is in?
    For example, if my Page was located at

    http://localhost/home/extrapages/misc/mypage.aspx

    it would return

    http://localhost/home/extrapages/misc/

    I need to be able to enter URLs relative to a page regardless of what
    directory the page is in, and throwing the ~/ in front of the relative
    directory only works if the page is located in the application root. Any
    ideas? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Gaurav Vaish (www.EduJiniOnline.com)"
    <> wrote in message
    news:...
    >> In the Page that uses this UserControl I pass it the value
    >> "images/bannerad.jpg". However, when I open the page, the
    >> Response.Write()

    >
    >> gets assigned to lnkAdvertisement.ImageUrl is
    >> 'usercontrols/images/bannerad.jpg'. Why is a different value being
    >> returned

    >
    > Probably because your page is within a folder 'usercontrols' related to
    > the application-root.
    > Prefer using the form "~/images/bannerad.jpg" instead.
    >
    >
    > --
    > Happy Hacking,
    > Gaurav Vaish | http://www.mastergaurav.com
    > http://www.edujinionline.com
    > http://articles.edujinionline.com/webservices
    > -------------------
    >
    >
    Nathan Sokalski, Sep 24, 2006
    #2
    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. Anders K. Jacobsen [DK]

    Sharing UserControls between different sites

    Anders K. Jacobsen [DK], Dec 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,235
    Bryce Budd
    Dec 8, 2004
  2. ujjc001
    Replies:
    0
    Views:
    1,370
    ujjc001
    Jul 27, 2005
  3. =?Utf-8?B?SmF2?=
    Replies:
    1
    Views:
    463
    =?Utf-8?B?SmF2?=
    Jul 11, 2006
  4. Nathan Sokalski

    UserControls in a different directory

    Nathan Sokalski, Sep 24, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    281
    Gaurav Vaish \(www.EduJiniOnline.com\)
    Sep 26, 2006
  5. Nathan Sokalski

    UserControls in a different directory

    Nathan Sokalski, Sep 24, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    112
    Nathan Sokalski
    Sep 24, 2006
Loading...

Share This Page