Professional Web Applications Themes

UserControls in a different directory - ASP.NET Building Controls

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.ResolveClie ntUrl(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 ...

  1. #1

    Default UserControls in a different directory

    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.ResolveClie ntUrl(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
    [email]njsokalskihotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]


    Nathan Sokalski Guest

  2. #2

    Default Re: UserControls in a different directory

    > 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 | [url]http://www.mastergaurav.com[/url]
    [url]http://www.edujinionline.com[/url]
    [url]http://articles.edujinionline.com/webservices[/url]
    -------------------


    Gaurav Vaish \(www.EduJiniOnline.com\) Guest

  3. #3

    Default Re: UserControls in a different directory

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

    [url]http://localhost/home/extrapages/misc/mypage.aspx[/url]

    it would return

    [url]http://localhost/home/extrapages/misc/[/url]

    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
    [email]njsokalskihotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]

    "Gaurav Vaish (www.EduJiniOnline.com)"
    <gaurav.vaish.nospamnospam.> wrote in message
    news:ucDYAk73GHA.2420TK2MSFTNGP02.phx.gbl...
    >> 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 | [url]http://www.mastergaurav.com[/url]
    > [url]http://www.edujinionline.com[/url]
    > [url]http://articles.edujinionline.com/webservices[/url]
    > -------------------
    >
    >

    Nathan Sokalski Guest

  4. #4

    Default Re: UserControls in a different directory

    > [url]http://localhost/home/extrapages/misc/mypage.aspx[/url]
    >
    > it would return
    >
    > [url]http://localhost/home/extrapages/misc/[/url]
    look at: HttpRequest::Url, HttpRequest::PathInfo and HttpRequest::Path
    You can obtain instance of HttpRequest from the Request property of the
    page.



    --
    Happy Hacking,
    Gaurav Vaish | [url]http://www.mastergaurav.com[/url]
    [url]http://www.edujinionline.com[/url]
    [url]http://articles.edujinionline.com/webservices[/url]
    -------------------


    Gaurav Vaish \(www.EduJiniOnline.com\) Guest

Similar Threads

  1. UserControls ASP.NET 2.0
    By Giovanni in forum ASP.NET Building Controls
    Replies: 0
    Last Post: April 24th, 11:16 PM
  2. Web UserControls and databinding...
    By fahad in forum ASP.NET Building Controls
    Replies: 0
    Last Post: August 2nd, 07:30 AM
  3. Abstract Usercontrols
    By tobiwan_kenobi in forum ASP.NET Building Controls
    Replies: 0
    Last Post: June 2nd, 11:05 PM
  4. Recursive UserControls? Are they possible?
    By Nathan in forum ASP.NET Building Controls
    Replies: 0
    Last Post: June 22nd, 01:18 AM
  5. Using UserControls in a DLL
    By Rory in forum ASP.NET Building Controls
    Replies: 5
    Last Post: July 29th, 07:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139