473,785 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2312
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 .ApplicationPat h%>/images/arrow.gif" ... />

There are alternatives, such as creating your own control:

public class Image : HtmlImage{
protected override Render(HtmlText Writer writer){
base.Src = Request.Applica tionPath + base.Src;
base.Render(wri ter)
}
}
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.ne t> wrote in message
news:u8******** ******@TK2MSFTN GP15.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
2218
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 root to be the root of the filesystem instead of the root of the cd. Any cd I make will need to run on Windows and Linux systems and the filesystems and the way the cd's are mounted are always different. For example: Windows root path for a...
1
5855
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 the no funny business can go on in the passed "path" that would produce a path not in the root (i.e. "..\..\dir1"). Here is my first stab at it, but not sure if this is too much or not enouph to ensure this. Any thoughts are welcome. TIA. ///...
4
7866
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 injected. If I specify a document-relative path (e.g., src="../someFolder/AnotherFolder/TheGraphic.gif"), then it works fine, but only for documents that exist at the level in the directory structure. I thought I could use a root-relative...
3
1570
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 to the application path as in ASP.NET so that links have the correct path relative to the web-site root." However, what do you do about ".css", ".js" links in your html? Dave.
2
2307
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 *current* page request? Here's what I'm doing: I am injecting HTML directly into ASPX pages via LiteralControl. something like this...
2
1366
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 http://localhost/WebApplication that contains a folder http://localhost/WebApplication/images
19
10239
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 when I deploy to a remote test server running real IIS, the real root of my application becomes: http://localhost/ What I want to do is have it so that on my local machine the asp.net dev
6
3350
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 needed here. I am using a relative path in the anchor such as: <a href= "/Common/ListView.aspx" My understanding is that I cannot use the syntax:
15
6471
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 make it much easier to slap modualar blocks of markup into page frameworks, which may change and so forth. And the few extra bytes, which even for a fairly large site would not amount to as many bytes as are in a fairly small low-res image, should...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.