Really noob question about asp:Image control

C

Chris Dunaway

I was looking over some asp.net code and saw this asp:Image control:

<asp:Image ImageUrl="~/images/logo.gif" runat="server" ID="Image1"/>


What does the tilde (~) mean in the ImageUrl attribute?

Is it some sort of relative addressing? On the design surface, that shows
as an error until I change it to read:

ImageUrl="../../images/logo.gif"

Which makes more sense to me. I have seen the tilde used this way
elsewhere too.

Can you enlighten a poor noob??

Thanks
 
M

Matt Berther

Hello Chris Dunaway dunawayc[[at]_lunchmeat_sbcglobal[dot]]net,

~ translates to application root. So, if youre website is:

http://localhost/MyWebApp/default.aspx

and you have an image located at http://localhost/MyWebApp/images/foo.gif, <asp:Image ImageUrl="~/images/foo.gif"> translates that path to /MyWebApp/images/foo.gif.

This is very nice for applications that may change their VROOT down the road.
I was looking over some asp.net code and saw this asp:Image control:

<asp:Image ImageUrl="~/images/logo.gif" runat="server" ID="Image1"/>

What does the tilde (~) mean in the ImageUrl attribute?

Is it some sort of relative addressing? On the design surface, that
shows as an error until I change it to read:

ImageUrl="../../images/logo.gif"

Which makes more sense to me. I have seen the tilde used this way
elsewhere too.

Can you enlighten a poor noob??

Thanks

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
C

Chris Dunaway

~ translates to application root. So, if youre website is:

http://localhost/MyWebApp/default.aspx

and you have an image located at http://localhost/MyWebApp/images/foo.gif, <asp:Image ImageUrl="~/images/foo.gif"> translates that path to /MyWebApp/images/foo.gif.

Visual Studio does not seem to handle those very well. It just displays a
box with a red X where the image would be displayed. Is there any way to
get VS to display those correctly?

Thanks again for the quick response
 

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
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top