473,388 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Specifying Root Relative Path in User Control

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">

The image appears just fine when viewed from pages that exist one directory
level below the site root, but not when viewed from pages that exist in the
site root (which is as expected).

What I want to do is be able to specify the path to the image in a way that
it does not matter where in the site's directory the page exists (the page
into which the user control is being inserted).

Specifying the path like this does NOT work:
<img src="~/images/arrow.gif" width="11" height="8" border="0">

So, what can I do?

Thanks!
Nov 19 '05 #1
1 2290
There are a handful of ways to solve this...

to get ~ to work, you need to stick a runat="server" on the img tag..

<img src="~/..." runat="server" ... />

you can also do somtehing like

<img src="<%=Request.ApplicationPath%>/images/arrow.gif" ... />

There are alternatives, such as creating your own control:

public class Image : HtmlImage{
protected override Render(HtmlTextWriter writer){
base.Src = Request.ApplicationPath + base.Src;
base.Render(writer)
}
}
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Guadala Harry" <GM**@NoSpam.net> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl...
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">

The image appears just fine when viewed from pages that exist one
directory level below the site root, but not when viewed from pages that
exist in the site root (which is as expected).

What I want to do is be able to specify the path to the image in a way
that it does not matter where in the site's directory the page exists (the
page into which the user control is being inserted).

Specifying the path like this does NOT work:
<img src="~/images/arrow.gif" width="11" height="8" border="0">

So, what can I do?

Thanks!

Nov 19 '05 #2

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

Similar topics

5
by: Jonathan | last post by:
I am creating a CD-ROM based website template. Things work fine under Windows but when I try to run the site under Linux the path is messed up. Therefore my JavaScript functions misinterpret the...
1
by: William Stacey [MVP] | last post by:
I need a bullet proof way to combine a root and a relative path to form a FQ rooted path (similar to a VDir in IIS). Path.Combine alone will not do the job in all cases. I also need to be sure...
4
by: Win, Pats | last post by:
I have a snippet of HTML that I inject into a number of pages throughout my Web site at runtime. My problem is that I'm not getting the image to appear in all documents into which this snippet is...
3
by: Dave | last post by:
Hi, since I'm developing on XP and can only have on website, how can you refer to your root application (not web) in your paths? I read for server controls that "the ~/ prefix will be converted...
2
by: Jordan Richard | last post by:
Put another way, is there any way I can tell ASP.NET to convert a path (imbedded in a string variable, "~/images/some_image.gif") to a root-relative path, that the client will understand, for the...
2
by: tsteinke | last post by:
Okay here is the situation I am developing a ASP.Net application locally and then I copy the project up to my web server. I start out by creating an ASP.NET Application ...
19
by: Steve Franks | last post by:
I am using VS.NET 2005 beta 2. When I run my project locally using the default ASP.NET Development Web Server it runs using a root address like this: http://localhost:11243/testsite/ However...
6
by: John Kotuby | last post by:
Hi all.. In a VS2005 ASP.NET 2.0 website application I am using a regular HTML anchor (actually a number of them) in a page that produces Excel output because a server control is really not...
15
by: Lars Eighner | last post by:
Aside from the deaths of a few extra electrons to spell out the whole root relative path, is there any down side? It seems to me that theoretically it shouldn't make any difference, and it would...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.