473,378 Members | 1,631 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,378 software developers and data experts.

using ~ (virtual path) with images

I made a header control in asp.net and it references images in the /images/
folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the controls
to load using the ~/tempates/ctrlHeader thing in the references section of
the page that uses them, but I need that same idea in the actual control so
it knows to refrence the image folder no mater where the page its doing it
from is located in the site... how can i do this? is there a way to use the
~ in the img src? thanks

example structure of this

/ root
|--- images
|--- controls for header etc...
| -- main page.html
|--- new pages in folder
| --- sub page 1.. references control header and img
Nov 18 '05 #1
12 1729
"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I made a header control in asp.net and it references images in the /images/ folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the controls to load using the ~/tempates/ctrlHeader thing in the references section of
the page that uses them, but I need that same idea in the actual control so it knows to refrence the image folder no mater where the page its doing it
from is located in the site... how can i do this? is there a way to use the ~ in the img src? thanks

example structure of this

/ root
|--- images
|--- controls for header etc...
| -- main page.html
|--- new pages in folder
| --- sub page 1.. references control header and img


Perhaps you should give an example of what you're talking about.
--
John Saunders
John.Saunders at SurfControl.com

Nov 18 '05 #2
If I understand your situation right, it should work if you make sure the
<img> tag runs on the server, and then use the ~ notation to get to the
images subdir,

e.g. <img src="~/images/pic.jpg" runat=server>

HTH,
Pete Beech

"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I made a header control in asp.net and it references images in the /images/ folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the controls to load using the ~/tempates/ctrlHeader thing in the references section of
the page that uses them, but I need that same idea in the actual control so it knows to refrence the image folder no mater where the page its doing it
from is located in the site... how can i do this? is there a way to use the ~ in the img src? thanks

example structure of this

/ root
|--- images
|--- controls for header etc...
| -- main page.html
|--- new pages in folder
| --- sub page 1.. references control header and img

Nov 18 '05 #3
Hi Brian,

The ~ syntax works with ASP.Net controls etc. but if you build your own URLs
this obviously won't work.

Take a look at this BLOG entry:

http://west-wind.com/weblog/posts/269.aspx

which talks about the various ASP.Net paths and also provides a generic
routine that lets you properly expand your own Urls using the ~ syntax.

Regards,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:#7**************@TK2MSFTNGP10.phx.gbl...
I made a header control in asp.net and it references images in the /images/ folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the controls to load using the ~/tempates/ctrlHeader thing in the references section of
the page that uses them, but I need that same idea in the actual control so it knows to refrence the image folder no mater where the page its doing it
from is located in the site... how can i do this? is there a way to use the ~ in the img src? thanks

example structure of this

/ root
|--- images
|--- controls for header etc...
| -- main page.html
|--- new pages in folder
| --- sub page 1.. references control header and img

Nov 18 '05 #4
thanks! that works great for img tag's.. is there anyway to also do this
with backgrounds of tables? runat=server doesnt seem to work on td tags with
background = "~/images/img.gif"

thanks!
"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
If I understand your situation right, it should work if you make sure the
<img> tag runs on the server, and then use the ~ notation to get to the
images subdir,

e.g. <img src="~/images/pic.jpg" runat=server>

HTH,
Pete Beech

"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I made a header control in asp.net and it references images in the

/images/
folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the

controls
to load using the ~/tempates/ctrlHeader thing in the references section of the page that uses them, but I need that same idea in the actual control

so
it knows to refrence the image folder no mater where the page its doing it from is located in the site... how can i do this? is there a way to use

the
~ in the img src? thanks

example structure of this

/ root
|--- images
|--- controls for header etc...
| -- main page.html
|--- new pages in folder
| --- sub page 1.. references control header and img


Nov 18 '05 #5
Hey Brian,

Don't forget the ASP.NET Table control...

<asp:Table id="Table1" runat="server" BorderWidth=1
BackImageUrl="~/images/floor.jpg">
<asp:TableRow>
<asp:TableCell>Hello</asp:TableCell>
<asp:TableCell></asp:TableCell>
</asp:TableRow>
<asp:TableRow></asp:TableRow>
<asp:TableRow></asp:TableRow>
</asp:Table>

Ken
Microsoft MVP [ASP.NET]
"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
thanks! that works great for img tag's.. is there anyway to also do this
with backgrounds of tables? runat=server doesnt seem to work on td tags
with
background = "~/images/img.gif"

thanks!
"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
If I understand your situation right, it should work if you make sure the
<img> tag runs on the server, and then use the ~ notation to get to the
images subdir,

e.g. <img src="~/images/pic.jpg" runat=server>

HTH,
Pete Beech

"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
> I made a header control in asp.net and it references images in the

/images/
> folder in the virtural path's root folder... How can I get the header
> control to show the images at any level of the web site? i got the

controls
> to load using the ~/tempates/ctrlHeader thing in the references section of > the page that uses them, but I need that same idea in the actual
> control

so
> it knows to refrence the image folder no mater where the page its doing it > from is located in the site... how can i do this? is there a way to use

the
> ~ in the img src? thanks
>
> example structure of this
>
> / root
> |--- images
> |--- controls for header etc...
> | -- main page.html
> |--- new pages in folder
> | --- sub page 1.. references control header and img
>
>




Nov 18 '05 #6
No, Brian, it won't work with tables. You can do something like this...

<table background='<%=ResolveUrl("~/images/image.jpg")%>'>
.... rest of table goes here
HTH
Brian W


"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
thanks! that works great for img tag's.. is there anyway to also do this
with backgrounds of tables? runat=server doesnt seem to work on td tags with background = "~/images/img.gif"

thanks!
"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
If I understand your situation right, it should work if you make sure the
<img> tag runs on the server, and then use the ~ notation to get to the
images subdir,

e.g. <img src="~/images/pic.jpg" runat=server>

HTH,
Pete Beech

"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I made a header control in asp.net and it references images in the /images/
folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the

controls
to load using the ~/tempates/ctrlHeader thing in the references
section of the page that uses them, but I need that same idea in the actual
control so
it knows to refrence the image folder no mater where the page its
doing
it from is located in the site... how can i do this? is there a way to

use the
~ in the img src? thanks

example structure of this

/ root
|--- images
|--- controls for header etc...
| -- main page.html
|--- new pages in folder
| --- sub page 1.. references control header and img



Nov 18 '05 #7
thanks, all your comments helped a lot

"Brian W" <brianw@gold_death_2_spam_rush.com> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
No, Brian, it won't work with tables. You can do something like this...

<table background='<%=ResolveUrl("~/images/image.jpg")%>'>
... rest of table goes here
HTH
Brian W


"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
thanks! that works great for img tag's.. is there anyway to also do this
with backgrounds of tables? runat=server doesnt seem to work on td tags

with
background = "~/images/img.gif"

thanks!
"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
If I understand your situation right, it should work if you make sure the <img> tag runs on the server, and then use the ~ notation to get to the images subdir,

e.g. <img src="~/images/pic.jpg" runat=server>

HTH,
Pete Beech

"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
> I made a header control in asp.net and it references images in the
/images/
> folder in the virtural path's root folder... How can I get the header > control to show the images at any level of the web site? i got the
controls
> to load using the ~/tempates/ctrlHeader thing in the references section
of
> the page that uses them, but I need that same idea in the actual

control so
> it knows to refrence the image folder no mater where the page its doing
it
> from is located in the site... how can i do this? is there a way to

use the
> ~ in the img src? thanks
>
> example structure of this
>
> / root
> |--- images
> |--- controls for header etc...
> | -- main page.html
> |--- new pages in folder
> | --- sub page 1.. references control header and img
>
>



Nov 18 '05 #8
Jos
"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I made a header control in asp.net and it references images in the /images/ folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the controls to load using the ~/tempates/ctrlHeader thing in the references section of
the page that uses them, but I need that same idea in the actual control so it knows to refrence the image folder no mater where the page its doing it
from is located in the site... how can i do this? is there a way to use the ~ in the img src? thanks

Yes. Add the attribute runat="server" to the <img> tag.
Of course, this will only work in .aspx files, not in .htm or .html files.

--

Jos
Nov 18 '05 #9
Hi Rick,
I had a quick look at your blog entry - I think ResolveURL will do the same
as your function, with regard to ~'s at the start of the URL.

Pete

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:OC**************@TK2MSFTNGP10.phx.gbl...
Hi Brian,

The ~ syntax works with ASP.Net controls etc. but if you build your own URLs this obviously won't work.

Take a look at this BLOG entry:

http://west-wind.com/weblog/posts/269.aspx

which talks about the various ASP.Net paths and also provides a generic
routine that lets you properly expand your own Urls using the ~ syntax.

Regards,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:#7**************@TK2MSFTNGP10.phx.gbl...
I made a header control in asp.net and it references images in the

/images/
folder in the virtural path's root folder... How can I get the header
control to show the images at any level of the web site? i got the

controls
to load using the ~/tempates/ctrlHeader thing in the references section of the page that uses them, but I need that same idea in the actual control

so
it knows to refrence the image folder no mater where the page its doing it from is located in the site... how can i do this? is there a way to use

the
~ in the img src? thanks

example structure of this

/ root
|--- images
|--- controls for header etc...
| -- main page.html
|--- new pages in folder
| --- sub page 1.. references control header and img


Nov 18 '05 #10
"Brian W" <brianw@gold_death_2_spam_rush.com> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
No, Brian, it won't work with tables. You can do something like this...

<table background='<%=ResolveUrl("~/images/image.jpg")%>'>
... rest of table goes here


Why wouldn't the following work:

<table runat="server" background="~/images/image.jpg">
....
</table>
--
John Saunders
John.Saunders at SurfControl.com

Nov 18 '05 #11
Why should it.
It works only in a handful amount of methods.
If some processing of the path is required then it works. If it's just a
property you set then it does not.

George.
"John Saunders" <john.saunders at SurfControl.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
"Brian W" <brianw@gold_death_2_spam_rush.com> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
No, Brian, it won't work with tables. You can do something like this...

<table background='<%=ResolveUrl("~/images/image.jpg")%>'>
... rest of table goes here


Why wouldn't the following work:

<table runat="server" background="~/images/image.jpg">
...
</table>
--
John Saunders
John.Saunders at SurfControl.com

Nov 18 '05 #12
Actually, it has to do with how the HTML server control was implemented.
Whoever wrote the code for System.Web.UI.HtmlControls.HtmlTable chose not to
resolve the path before rendering.
Regards
Brian W

"John Saunders" <john.saunders at SurfControl.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
"Brian W" <brianw@gold_death_2_spam_rush.com> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
No, Brian, it won't work with tables. You can do something like this...

<table background='<%=ResolveUrl("~/images/image.jpg")%>'>
... rest of table goes here


Why wouldn't the following work:

<table runat="server" background="~/images/image.jpg">
...
</table>
--
John Saunders
John.Saunders at SurfControl.com

Nov 18 '05 #13

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

Similar topics

9
by: Brian Henry | last post by:
I made a header control in asp.net and it references images in the /images/ folder in the virtural path's root folder... How can I get the header control to show the images at any level of the web...
1
by: Ibrahim | last post by:
I have made an Aplication use VPP and make deploy for it on IIS on windows 2003 Server 1- built the web Application with Asp.net2 2- Implement the Virtual path provider (Virtual path , virtual...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.