UserControls in a different directory

Ask a Question related to ASP.NET Building Controls, Design and Development.

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


    Nathan Sokalski Guest

  2. Similar Questions and Discussions

    1. UserControls ASP.NET 2.0
      Hi All, What is the best way to develop and use UserControls on an ASPX page with the new dynamic compilation model introduced in ASP.NET 2.0? ...
    2. Abstract Usercontrols
      We have some questions about 'abstract' and 'usercontrol'. A project that we are working on has user controls that are marked as abstract. 1. ...
    3. Recursive UserControls? Are they possible?
      I am trying to implement something similar to a treeview in an asp.net usercontrol. As this control has no need to allow multiple branches to be...
    4. UserControls in datagrid
      Vincent Destombes wrote: Do you rebind your datagrid on postback? If you don't, the itemcreated event will not be called on postback, and your...
    5. Using UserControls in a DLL
      You need to create a refrence to the usercontrol project (assuming you created this in vs.net) in your current projects refrences. Alternatively,...
  3. #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

  4. #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]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]

    "Gaurav Vaish (www.EduJiniOnline.com)"
    <gaurav.vaish.nospam@nospam.gmail.com> wrote in message
    news:ucDYAk73GHA.2420@TK2MSFTNGP02.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

  5. #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

Posting Permissions

  • You may not post new threads
  • You may 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