473,462 Members | 1,070 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

User control + relative path

Hi. I need some help on this.
I have a user control (a header) in my root directory, and all my pages use
that control. Then a created a folder (in my root directory) and put a new
page inside it, and that page use the same control, but this time the
control can't find it's images and resources because it is trying to find it
in the same folder instead of the root directory. Now, I know that I can
change the control image's relative paths for absolute paths, but then when
I upload my application to the real server I have to change all the paths
again. Of course I could make a copy of the control in my new folder but
then I have to copy all the images and everything too.
Is there some simple way of dealing with that?
Thanks,
Alejandro Penate-Diaz.


Nov 18 '05 #1
2 2348
Alex wrote:
Hi. I need some help on this.
I have a user control (a header) in my root directory, and all my pages use
that control. Then a created a folder (in my root directory) and put a new
page inside it, and that page use the same control, but this time the
control can't find it's images and resources because it is trying to find it
in the same folder instead of the root directory. Now, I know that I can
change the control image's relative paths for absolute paths, but then when
I upload my application to the real server I have to change all the paths
again. Of course I could make a copy of the control in my new folder but
then I have to copy all the images and everything too.
Is there some simple way of dealing with that?


Alex, the best approach is to use either:

(a) Absolute paths (i.e., not relative ones)
(b) The ~ character in your Web controls

For (a), what this would mean, is rather than your paths being things like:

<img src="../images/red.gif" />

-or-

<img src="img/blue.jpg" />

You'd instead use fully qualified, absolute paths, like:

<img src="/Foo/Dir2/images/blue.gif" />

The problem with this is if you have a Web application on your local
server at /Foo, but this will be moved to / when you deploy it. Then
/Foo/Dir2/images will become /Dir2/images when you deploy...

To solve for this problem, use the second approach listed. What you can
do is add ~ in your Web controls, which will cause the path to be
resolved automagically at runtime. So, if you have an Image web control
you could specify the path like:

<asp:Image ImageUrl="~/images/blue.gif" />

This only works in Web controls (not static HTML markup).

hth

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2
Thanks a lot. I think that I should use server controls instead of html
images, or better, I will use skmMenu instead of mine. ;-).
thanks, Alejandro Penate-Diaz.


"Scott Mitchell [MVP]" <mi******@4guysfromrolla.com> wrote in message
news:41**************@4guysfromrolla.com...
Alex wrote:
Hi. I need some help on this.
I have a user control (a header) in my root directory, and all my pages use that control. Then a created a folder (in my root directory) and put a new page inside it, and that page use the same control, but this time the
control can't find it's images and resources because it is trying to find it in the same folder instead of the root directory. Now, I know that I can
change the control image's relative paths for absolute paths, but then when I upload my application to the real server I have to change all the paths again. Of course I could make a copy of the control in my new folder but
then I have to copy all the images and everything too.
Is there some simple way of dealing with that?
Alex, the best approach is to use either:

(a) Absolute paths (i.e., not relative ones)
(b) The ~ character in your Web controls

For (a), what this would mean, is rather than your paths being things

like:
<img src="../images/red.gif" />

-or-

<img src="img/blue.jpg" />

You'd instead use fully qualified, absolute paths, like:

<img src="/Foo/Dir2/images/blue.gif" />

The problem with this is if you have a Web application on your local
server at /Foo, but this will be moved to / when you deploy it. Then
/Foo/Dir2/images will become /Dir2/images when you deploy...

To solve for this problem, use the second approach listed. What you can
do is add ~ in your Web controls, which will cause the path to be
resolved automagically at runtime. So, if you have an Image web control
you could specify the path like:

<asp:Image ImageUrl="~/images/blue.gif" />

This only works in Web controls (not static HTML markup).

hth

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Adie | last post by:
Hi, I wonder if anyone can tell me how to add user controls to a page dynamically? In context: I have a bunch of HTML tables which due to time constraints can't be populated to a database, so I...
4
by: Remi Hugnon | last post by:
Hi, I want to build an expandable treeview. I saw some code on VB but I know only C# I plan for my class that each nodes has its own id (using span for example). Into a single aspx page...
1
by: Dave | last post by:
I've built a custom server control that reads an xml file and builds a left side navigation system. When I drop that server control into a user control that will hold the left side navigation for...
1
by: Guadala Harry | last post by:
I have a user control that I'm inserting into multiple pages. Part of the HTML content in the user control is a path to an image: <img src="../images/arrow.gif" width="11" height="8" border="0">...
8
by: Paul Bromley | last post by:
I am trying to get somewhere with user controls and have come up against an obstacle with using relative paths. I have a dataset in my user control, and have tried to enter the path with the...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
4
by: =?Utf-8?B?Qkw=?= | last post by:
I am in a problem to access user control(.ascx) on a .aspx page the following is my scenario I have following directory structure - Autoboom - workshop -- WSFirst -showroom
1
by: gnewsgroup | last post by:
I have a user control called Footer.ascx, in which a background image is inserted like so: <div id="footerdiv" style="background-image:url('Images/ mybackground.jpg');...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.