Path problems with an ascx file

T

tshad

I have an ascx file I am using to include my logos and heading information
for all my pages.

It was working fine up until now.

I decided to set up an admin folder inside of my main folder and move one of
my files into it - now my links don't work.

I have a setup:

development
images
includes
staffing
admin

To get to my includes folder (where the ascx file is) I would use;

<%@ Register TagPrefix="fts" TAgName="header"
src="..\includes\ClientHeaders.ascx" %>

This worked fine.

But now I have the file in a folder one level down inside my staffing folder
(admin).

I now change the entry to:

<%@ Register TagPrefix="fts" TAgName="header"
src="..\..\includes\ClientHeaders.ascx" %>

This works fine as far as finding the file. The problem is that the
relative paths are not relative to where the ascx file is but where my aspx
page is (which is now one level down).

For example, in my ClientHeaders.ascx file I have the following:

<table width="100%" class="tableMain" border="0" cellspacing="0"
cellpadding="0">
<tr width="424" height="90" valign="top">
<td width="424px"><img src="..\images\masthead3.jpg" width="246"
height="74px">

It can fine the masthead3.jpg fine from staffing (where it used to be). But
now the file is really "..\..\images\masthead3.jpg".

How do I use the sam ascx file in both folders (or can I)?

Thanks,

Tom
 
M

Marina

What about always making the path something like
"~\includes\ClientHeaders.ascx", so it is always relative to the root
folder.
 
B

Brock Allen

Same thing for the <img> tags, but you need to make them runat=server:

<img runat=server src="~/images/foo.jpg">
 
T

tshad

Marina said:
What about always making the path something like
"~\includes\ClientHeaders.ascx", so it is always relative to the root
folder.

I tried that, but I can never get to make it work consistantly.

I can get it to work here:

<%@ Register TagPrefix="fts" TAgName="header"
src="~\includes\ClientHeaders.ascx" %>
<%@ Register TagPrefix="fts" TAgName="footer"
src="~\includes\staffingFooters.ascx" %>

But it doesn't work for my images or my include file:

<!-- #include file="~\includes\slidemenus.inc" -->

Here I get an error message:

Parser Error Message: Could not find a part of the path
"C:\Inetpub\wwwroot\workshop\Dev\staffing\Admin\~\includes\slidemenus.inc".

Why does it work in one and not the other?

Tom
 
B

Brock Allen

Otherwise the "~/images/foog.jpg" doesn't automatically get resolved based
upon the application root.
 
B

Brock Allen

Server side includes are strongly discouraged in ASP.NET. Use User Controls
(ASCX files) instead -- they're much more efficient.
 

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

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top