Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - ASPNET2: Master Page File Reference Problem

 
Thread Tools Search this Thread
Old 02-03-2006, 12:25 AM   #1
Default ASPNET2: Master Page File Reference Problem


I have some img tags on a master page which reference files in a top-level directory. They look like this:

<img src="assets/test.gif" id="gnr" />

assets is a subdirectory of the website root.

My problem is this: this kind of path reference in a master page won't work when the page using the master is not in the root
folder:

root_page.aspx <- if this uses the master, the image file will be located and displayed correctly
subdirectory/subdir_page.aspx <- if this uses the master, it won't locate and display the image file

One solution I've used before is to change the image tag as follows:

<img runat="server" src="~/assets/test.gif" id="gnr" />

This lets the file be found...but unfortunately it makes the img tag not respond to CSS positioning attributes. Specifically, even
though the gnr id is defined as being absolutely positioned at the right margin (within relatively positioned div element), it still
floats on the left.

I'm pretty sure this is a bug.

But I'd love to hear how to work around it. Anyone got any ideas? Other than switching to <asp:image> tags; I got that to work
already.

- Mark


Mark Olbert
  Reply With Quote
Old 02-03-2006, 01:44 AM   #2
Mark Fitzpatrick
 
Posts: n/a
Default Re: ASPNET2: Master Page File Reference Problem
Mark,
One of the ways I get around it is to simply embed a <%
Response.Write(Request.ApplicationPath)); %> right in the src attribute like
so:
<img src="<% Response.Write(Request.ApplicationPath)); %>assets/test.gif"
id="gnr" />

You can also simply add the runat="server" attribute to the image tag
and it will then cause the server to process the location at runtime so it
will determine how to correctly reference it.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage


"Mark Olbert" <> wrote in message
news:...
>I have some img tags on a master page which reference files in a top-level
>directory. They look like this:
>
> <img src="assets/test.gif" id="gnr" />
>
> assets is a subdirectory of the website root.
>
> My problem is this: this kind of path reference in a master page won't
> work when the page using the master is not in the root
> folder:
>
> root_page.aspx <- if this uses the master, the image file will be located
> and displayed correctly
> subdirectory/subdir_page.aspx <- if this uses the master, it won't locate
> and display the image file
>
> One solution I've used before is to change the image tag as follows:
>
> <img runat="server" src="~/assets/test.gif" id="gnr" />
>
> This lets the file be found...but unfortunately it makes the img tag not
> respond to CSS positioning attributes. Specifically, even
> though the gnr id is defined as being absolutely positioned at the right
> margin (within relatively positioned div element), it still
> floats on the left.
>
> I'm pretty sure this is a bug.
>
> But I'd love to hear how to work around it. Anyone got any ideas? Other
> than switching to <asp:image> tags; I got that to work
> already.
>
> - Mark





Mark Fitzpatrick
  Reply With Quote
Old 02-03-2006, 06:46 AM   #3
Steven Cheng[MSFT]
 
Posts: n/a
Default Re: ASPNET2: Master Page File Reference Problem
Hi Mark,

You can also use the Page.ResolveUrl function to interpret the "~/xxxx"
url, e.g:

<img src='<%= ResolveUrl("~/Images/test.gif")%>' alt="test gif"/><br />

Hope also helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Steven Cheng[MSFT]
  Reply With Quote
Old 02-04-2006, 05:31 PM   #4
clintonG
 
Posts: n/a
Default Re: ASPNET2: Master Page File Reference Problem
Its not a bug. This time it really is by design although the design imposes
a conflict with the CSS id selector. As used by the framework, the id
functions as an attribute the compiler needs to build the control tree when
the page is compiled.

The solution is to stop depending on the id selector to apply sytle. Use the
class selector. The id selector has no real value other than its intended
use to identify a once and only once instance in the page. No big deal as
inheritence, cascade and specificity are not affect one iota when not using
id selectors for style.

All the other inclie code block hacks are fine and well to know and have at
hand but simply using class selectors resolves this misperceived bug. Note
there is also something to be learned about class selectors when using
Themes which over-ride inline declarations...

// example when not using Themes which will over-ride the inline class
selector
<img src="~/assets/test.gif" id="gnr" class="ClassName" runat="server"/>

// example when using Themes
<img src="~/assets/test.gif" id="gnr" SkinID="ClassName" />
// .skin file entry
<asp:Image SkinID="ClassName" CssClass="ClassName" runat="server" />

There's more to discuss and learn of course but these points should at least
point you in the right direction with no hacks required noting again, they
are good to know and learn but sometimes not needed.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/



"Mark Olbert" <> wrote in message
news:...
>I have some img tags on a master page which reference files in a top-level
>directory. They look like this:
>
> <img src="assets/test.gif" id="gnr" />
>
> assets is a subdirectory of the website root.
>
> My problem is this: this kind of path reference in a master page won't
> work when the page using the master is not in the root
> folder:
>
> root_page.aspx <- if this uses the master, the image file will be located
> and displayed correctly
> subdirectory/subdir_page.aspx <- if this uses the master, it won't locate
> and display the image file
>
> One solution I've used before is to change the image tag as follows:
>
> <img runat="server" src="~/assets/test.gif" id="gnr" />
>
> This lets the file be found...but unfortunately it makes the img tag not
> respond to CSS positioning attributes. Specifically, even
> though the gnr id is defined as being absolutely positioned at the right
> margin (within relatively positioned div element), it still
> floats on the left.
>
> I'm pretty sure this is a bug.
>
> But I'd love to hear how to work around it. Anyone got any ideas? Other
> than switching to <asp:image> tags; I got that to work
> already.
>
> - Mark





clintonG
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Burn process failed - help! Log file posted for help troubleshooting Michael Mason DVD Video 1 08-16-2004 09:24 PM
DeepdiscountDVD problem loading home page today? JAM DVD Video 2 05-21-2004 11:22 PM
How do I split a mpeg-2 file, then recombine to get the same thing? William Richardson DVD Video 5 12-18-2003 02:17 PM
DeepDiscountDVD Cart Page problem MikeXP DVD Video 31 12-08-2003 01:29 AM
Pioneer A05 Problems Bill Stock DVD Video 8 11-28-2003 05:03 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46