ASP.NET 2 Master Pages - Files reference

otherside

Centurion
Joined
Mar 16, 2003
Messages
127
Location
UK - Greece
Hey guys,

I have to say ASP.NET v2 is great, fantastic new controls, vs2005 is way better than 2003 etc...

But there are issues...

1. Some controls will still produce code not compatible with XHTM and though validation will fail. Anyway that's not the point of the this thread.

Here is my problem.

Master pages, yeap great new feature.

But how on earth are you supposed to refence your files.

say images, scripts etc.

Example

you have the following folder structure:
Code:
Root+
        mymaster.master
        images+
                   img.gif
        pages+
                  page1.aspx
                  english+
                             page2.aspx
        Scripts+
                 functions.js

if you place an image like:

<img src="/images/img.gif" />

in the master page, on page1 and page2 that have the mymaster.master as master the reference to the image will be incorrect.

Ok ok say you use asp controls for this. <asp:image> etc.. yeah that works....

but what happens when its other stuff like an external javascript file.

i put the script inside <head>

<script type="text/javascript" language="javascript" src="Scripts/functions.js">
</script>

page1 and page2 are trying to find the script on /pages/Scripts and /pages/English/scripts respectively, when it is on /Scripts.


also what about in-line styles ?

<div style="background-image:url(Images/img.gif)"></div>


Is there any solution?

am i missing something ?
 
Last edited:
If you're using standard non server-side html elements, they will function exactly the same way HTML functions. It doesn't matter where the master page is. You're not calling the master page directly; you're calling the page directly. Therefore, you link to resources in regard to where your page (.aspx) is located, not where the master page, or even user control is located.
 
Back
Top