how do I navigate UP the directory tree from a subfolder?

K

Keith G Hicks

asp.net 2.0

I have a master page in my root. I have some other pages in subfolders. All
my navigation buttons are on the master page. When I click one of the
buttons that takes me to a page in a subfolder, that works fine. But then
when I click one of the buttons that's supposed to take me back up (to the
home page for example), it cannot find it. I understand why but I don't know
what to do to handle it. No idea. Could someone give me some specific info
on what to do? I tried searching online for an answer but I'm not even sure
what to search for. I'm sure this is a common thing so it can't be terribly
complicated.

Thanks,

Keith
 
K

Keith G Hicks

I should mention that if I use an asp:button with the PostBackURL set to
something like "~/Home.aspx" it works but I have several img controls on the
page that have <a href="~/Home.aspx" ... in them as follows:

<a href="~/Home.aspx" onmouseover="setOverImg('1','');"
onmouseout="setOutImg('1','');" target=""> <img runat="server"
src="MasterPageSideButtons/button1up.png" border="0" id="button1" vspace="1"
hspace="1"></a><br>

These are the buttons that don't work. THey function fine as long as I'm on
a page that's in the root, but as soon as I'm on a page that's in a
subdirectory, they throw an error.

Keith
 
M

Mark Rae [MVP]

These are the buttons that don't work. They function fine as long as I'm
on
a page that's in the root, but as soon as I'm on a page that's in a
subdirectory, they throw an error.

As a general rule in a technical newsgroup, there's very little point in
saying something like "they throw an error" if you don't actually tell the
group what the error is - I wrote some code this morning but, when I ran it,
it threw an error - what could the problem be...?

Please say what the error is that you're getting...
 
K

Keith G Hicks

Don't answer people if all you can be is rude. I thought I stated the
problem pretty clearly in the original post and that because asp.net is new
to me I wasn't sure what to ask about exactly. I said "it cannot find the
page." I figured I didn't need to repeat that in my follow up. Iv'e been
writing and answering newsgroup messages for years in microsoft, borland and
various 3rd party tools. I don't need a scolding on how to be clear in a
post. I read posts all the time that are so far from clear that it's
laughable. Same for a lot fo the answers I see. I figured this is a common
issue and describing the fact that I have img controls on the master page
wiht <a href... /> links in them and that they can't navigate back up to the
root directory when on a page that's in a subfolder was super clear and
probably something that is easy for experienced asp.net folks (especially
MVP's) to solve. Does anyone have a helpful answer to my problem?

And if it helps, here's all the error info:

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make sure that
it is spelled correctly.

Requested URL: /Website1/LoggedInUsers/Home.aspx

---------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.42


The page "Home.aspx" is actually in the root ("Website1"), not in the
"LoggedInUsers"
directory.

Keith
 
M

Mark Rae [MVP]

And if it helps, here's all the error info:

It does.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make sure
that
it is spelled correctly.

Requested URL: /Website1/LoggedInUsers/Home.aspx

Looks very much like you have a relative addressing problem. One of the
resources that your page is looking for is not in the folder where the code
is expecting to find it...

Simplest way to track it down would be to do a View Source on the page where
the error occurs and inspect the URL paths in the HTML output...
 
K

Keith G Hicks

I changed the url in the images so they include the root hard coded into
them (I added /MySiteRoot/ to the href).

<a href="/MySiteRoot/Home.aspx"
onmouseover="setOverImg('1','');"onmouseout="setOutImg('1','');"target="">
<img runat="server" src="MasterPageSideButtons/button1up.png" border="0"
id="button1" vspace="1" hspace="1">
</a>

That did the trick. I read that I also needed runat="server" in the img tags
for images that are on the master page otherwise they won't show up when
viewing a content page in a subfolder. That handled that problem. Before I
did that, the image MasterPageSideButtons/button1up.png didn't appear
because it's in a folder above the page i was viewing. Would something
similar handle the problem above (the one I originally posted about) or was
adding /MySiteRoot/ the correct thing to do?

Keith
 
M

Mark Rae [MVP]

I changed the url in the images so they include the root hard coded into
them (I added /MySiteRoot/ to the href).

<a href="/MySiteRoot/Home.aspx"
onmouseover="setOverImg('1','');"onmouseout="setOutImg('1','');"target="">
<img runat="server" src="MasterPageSideButtons/button1up.png" border="0"
id="button1" vspace="1" hspace="1">
</a>

That did the trick. I read that I also needed runat="server" in the img
tags
for images that are on the master page otherwise they won't show up when
viewing a content page in a subfolder. That handled that problem. Before I
did that, the image MasterPageSideButtons/button1up.png didn't appear
because it's in a folder above the page i was viewing. Would something
similar handle the problem above (the one I originally posted about) or
was
adding /MySiteRoot/ the correct thing to do?

The easiest thing to do would be to use webcontrols e.g. <asp:HyperLink> or,
as you say, to add runat="server" to the HTML controls and to use the tilde
(~) character as shorthand for the virtual root rather than hard-coding it
by name:
http://www.google.co.uk/search?sour...rlz=1T4GZEZ_en-GBGB252GB252&q="ASP.NET"+tilde
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top