Hyperlink control in user control

Discussion in 'ASP .Net' started by =?Utf-8?B?Y2dhbWJpbm8=?=, Mar 22, 2007.

  1. Hello,

    I am having what I think is a problem with hyperlinks in user controls. My
    usercontrol is in my Controls/NavControls directory. The page that I have
    consuming the control is in my Pages/PageInfo/ directory.

    My control, PageNav.ascx has an asp:hyperlink control on it that sets the
    NavigateUrl property dynamically. I want to set it to a local reference,
    something like: <a href="page2.aspx">Page2</a> or having it generate to:
    http://mysite/Pages/PageInfo/page2.aspx would work as well.

    However, it seems that the hyperlink is generating is to the Control's
    directory, instead of the consuming page directory.. ie it is rendering to <a
    href="http://mysite/Controls/NavControls/page2.aspx">Page2</a> ... which is
    not a valid page.

    Does anyone know if there are any properties I can set to make this work
    like I want? Or is there some code involved that I'd have to put in.

    Thanks
     
    =?Utf-8?B?Y2dhbWJpbm8=?=, Mar 22, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?Y2dhbWJpbm8=?=

    Mark Rae Guest

    "cgambino" <> wrote in message
    news:...

    > I am having what I think is a problem with hyperlinks in user controls.
    > My
    > usercontrol is in my Controls/NavControls directory. The page that I
    > have
    > consuming the control is in my Pages/PageInfo/ directory.
    >
    > My control, PageNav.ascx has an asp:hyperlink control on it that sets the
    > NavigateUrl property dynamically. I want to set it to a local reference,
    > something like: <a href="page2.aspx">Page2</a> or having it generate to:
    > http://mysite/Pages/PageInfo/page2.aspx would work as well.
    >
    > However, it seems that the hyperlink is generating is to the Control's
    > directory, instead of the consuming page directory.. ie it is rendering to
    > <a
    > href="http://mysite/Controls/NavControls/page2.aspx">Page2</a> ... which
    > is
    > not a valid page.
    >
    > Does anyone know if there are any properties I can set to make this work
    > like I want? Or is there some code involved that I'd have to put in.


    <a href="../../Pages/PageInfo/page2.aspx">Page2</a>
     
    Mark Rae, Mar 22, 2007
    #2
    1. Advertising

  3. =?Utf-8?B?Y2dhbWJpbm8=?=

    GroupReader Guest

    I agree with Mark Rae, but to elaborate a bit more....

    The behavior that you are describing is by design and should be what
    you want. You want all the paths to be relative from the User
    Control, and *not* from the containing page. That way you can re-use
    your user control on multiple pages without breaking all the paths.
    Sound right?

    So, what people normally do is use the ".." operator to back up one
    directory as in href="..\images\myimage.gif".

    See also: the tilde "~" as used in paths and the "ResolveUrl() and
    ResolveClientUrl() methods". You shouldn't have to use these though.
    You can also start a path with "/" to say that your are starting from
    the root of your website. The root might change, though, if you
    deploy to different servers/environments.
     
    GroupReader, Mar 22, 2007
    #3
    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. James P.
    Replies:
    4
    Views:
    510
    James P.
    Jun 15, 2004
  2. mimi
    Replies:
    1
    Views:
    440
    souri challa
    Jul 8, 2005
  3. davetichenor
    Replies:
    1
    Views:
    909
    Eliyahu Goldin
    Oct 30, 2006
  4. Ken
    Replies:
    1
    Views:
    427
    Alvin Bruney
    Aug 16, 2003
  5. Dave
    Replies:
    0
    Views:
    998
Loading...

Share This Page