link URL confusion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith G Hicks

    link URL confusion

    I'm confused about how to code a link button to go to the page I need
    (asp.net 2.0)

    My root is "Website1"

    Here's the layout for the purposes of this question:

    Website1 (folder)
    masterpage.mast er (in the root)

    Admin (folder off the root)
    SendMail.aspx (uses the master)

    LoggedInUsers (folder off the root)
    EditLoginInfo.a spx (uses the master)

    Default.aspx (this is in the root and also uses the master)

    Most of the pages are in the root including the master page. All the pages
    in the system use that master page.

    On the master page I have a line of text like this:

    <a href="LoggedInU sers/EditLoginInfo.a spx">Edit Login Info</a>

    When I'm on the Default.aspx page and click the link, it goes to the page I
    expect it to. However, when I'm on the SendMail.aspx page and I click the
    "Edit Login Info" link, I get the error: "The resource cannot be found"
    Requested URL: /Website1/Admin/LoggedInUsers/EditLoginInfo.a spx

    I understand why because obviously there's no such folder layout as
    /Website1/Admin/LoggedInUsers/ so it's not finding the page but I don't know
    what to change to make it work. If I change the link to read

    <a href="~/LoggedInUsers/EditLoginInfo.a spx">Edit Login Info</a>

    I get the same error: "The resource cannot be found"

    and:

    Requested URL: /Website1/Admin/~/LoggedInUsers/EditLoginInfo.a spx

    Now what's really confusing to me is if I use a LinkButton instead of just
    text with href, and set the PostBackUrl in the button as follows:

    PostBackUrl="~/LoggedInUsers/EditLoginInfo.a spx"

    then that link button works fine no matter where I am in the site. Doesn't
    matter what folder I'm in, it always finds the page I need.

    Do I have to use link buttons with PostBackUrl whenever I'm dealing with
    master pages and subfolders or is there a way to use href in text and get
    this to work right?

    I hope I've made the problem clear enough.

    Thanks,

    Keith




  • Keith G Hicks

    #2
    Re: link URL confusion

    I should point out that if I put the root in the <a href ... like this:

    <a href="/Wesite1/LoggedInUsers/EditLoginInfo.a spx">Edit Login Info</a>

    It works fine, but everthing I read says it's bad practice to hardcode the
    root anywhere.

    Keith


    Comment

    • Jesse Houwing

      #3
      Re: link URL confusion

      Hello Keith,

      You can use the <asp:hyperlin k /control to add a link to a different page.
      it has a property in which you can set the url using the ~/path notation.
      The hyperlink control will automatically resolve the url to teh correct value
      depending on which page is using the masterpage. Just like your LinkButton
      is doing. Another thing you could try is to set the runat="server" attribute
      on your <a href=".."tags.

      --
      Jesse Houwing
      jesse.houwing at sogeti.nl
      I'm confused about how to code a link button to go to the page I need
      (asp.net 2.0)
      >
      My root is "Website1"
      >
      Here's the layout for the purposes of this question:
      >
      Website1 (folder)
      masterpage.mast er (in the root)
      Admin (folder off the root)
      SendMail.aspx (uses the master)
      LoggedInUsers (folder off the root)
      EditLoginInfo.a spx (uses the master)
      Default.aspx (this is in the root and also uses the master)
      >
      Most of the pages are in the root including the master page. All the
      pages in the system use that master page.
      >
      On the master page I have a line of text like this:
      >
      <a href="LoggedInU sers/EditLoginInfo.a spx">Edit Login Info</a>
      >
      When I'm on the Default.aspx page and click the link, it goes to the
      page I expect it to. However, when I'm on the SendMail.aspx page and I
      click the "Edit Login Info" link, I get the error: "The resource
      cannot be found" Requested URL:
      /Website1/Admin/LoggedInUsers/EditLoginInfo.a spx
      >
      I understand why because obviously there's no such folder layout as
      /Website1/Admin/LoggedInUsers/ so it's not finding the page but I
      don't know what to change to make it work. If I change the link to
      read
      >
      <a href="~/LoggedInUsers/EditLoginInfo.a spx">Edit Login Info</a>
      >
      I get the same error: "The resource cannot be found"
      >
      and:
      >
      Requested URL: /Website1/Admin/~/LoggedInUsers/EditLoginInfo.a spx
      >
      Now what's really confusing to me is if I use a LinkButton instead of
      just text with href, and set the PostBackUrl in the button as follows:
      >
      PostBackUrl="~/LoggedInUsers/EditLoginInfo.a spx"
      >
      then that link button works fine no matter where I am in the site.
      Doesn't matter what folder I'm in, it always finds the page I need.
      >
      Do I have to use link buttons with PostBackUrl whenever I'm dealing
      with master pages and subfolders or is there a way to use href in text
      and get this to work right?
      >
      I hope I've made the problem clear enough.
      >
      Thanks,
      >
      Keith
      >

      Comment

      Working...