Problem with an IMG from a Master Page

G

Guest

This seems like it should be so simple but I really can't figure out what's
going on:

I have a simple MasterPage. On that page I want to place an Image (IMG or
asp:Image, doesn't really matter to me). But for some reason, the image won't
come up because the path (src) for that image in the actual page displayed
isn't right. In the "src," I've tried using a path that starts with the "~"
(src="~/Shared/Images/xyz.jpg") and a path that is relative to the MasterPage
(src="../Images/xyz.jpg"). In both cases, I just don't get the right path at
output. The IMG tag is set as runat="server" and all that so I just can't
figure out what's going wrong here.

I'm starting to think that this has to do with the path of the actual page
displayed as opposed to the path from the MasterPage but that doesn't really
make a lot of sense either. Any thoughts?

Alex
 
R

Ray Booysen

Alex said:
This seems like it should be so simple but I really can't figure out what's
going on:

I have a simple MasterPage. On that page I want to place an Image (IMG or
asp:Image, doesn't really matter to me). But for some reason, the image won't
come up because the path (src) for that image in the actual page displayed
isn't right. In the "src," I've tried using a path that starts with the "~"
(src="~/Shared/Images/xyz.jpg") and a path that is relative to the MasterPage
(src="../Images/xyz.jpg"). In both cases, I just don't get the right path at
output. The IMG tag is set as runat="server" and all that so I just can't
figure out what's going wrong here.

I'm starting to think that this has to do with the path of the actual page
displayed as opposed to the path from the MasterPage but that doesn't really
make a lot of sense either. Any thoughts?

Alex

Using ~ will bring you to the application root, so if you use an
asp:image with the image url set to "~/images/xxx.jpg" that should point
to application root/images/xxx.jpg.
 
E

Edwin Knoppert

(IMG or asp:Image, doesn't really matter to me).

That's exactly the issue, an asp image control will handle virtual folders
having ~/...
 
W

Walter Wang [MSFT]

Hi Alex,

Thank you for posting!

I've found a detailed article regarding how to reference images in master
pages:

#Master Pages: Master Your Site Design with Visual Inheritance and Page
Templates
http://msdn.microsoft.com/msdnmag/issues/04/06/ASPNET20MasterPages/

Search for the "Details of Usage" part.

Either using root path reference syntax or still using relative path, the
key is to use server-side controls.

Hope this helps.


Regards,

Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top