469,317 Members | 1,739 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,317 developers. It's quick & easy.

java <script> include in Master pages - src is not mapped

Hello,

I have simple in one folder FolderA

MyMaster.master and
script01.js
styles01.css

The content pages are in

FolderA/FolderB/ContentPage01.aspx
and
FolderA/FolderB/FolderC/ContentPage02.aspx

in MyMaster.master I have so

<link href="styles01.css" type="text/css" rel="Stylesheet" />
<script type="text/javascript" src="script01.js"></script>

Now if I call ContentPage01

I see in the generated source css ref is correct maped to ../styles01.css
but javascript include not, it is script01.js
must be ../script01.ja

The same if I call ContentPage02
I see in the generated source css ref is correct maped to
.../../styles01.css
but javascript include not, it is script01.js
must be ../../script01.ja

I can in my design only use relativ pathes no other.
Why is stylesheet include mapped correctly and javascript include is not ?
What to do?

Thank you
Rolf Welskes
Aug 23 '06 #1
2 1714
Rolf,
Try adding the runat="server" attribute to the script tag. The
easier one I do though is placing a Response.Write(Request.ApplicationPath)
inline in the src attribute such as:

<script type="text/javascript" src="<%
Response.Write(Request.ApplicationPath); %>script01.js"></script>

It's a bit old-school, but it works ok.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Rolf Welskes" <ro**@nospam.nospamwrote in message
news:uO**************@TK2MSFTNGP03.phx.gbl...
Hello,

I have simple in one folder FolderA

MyMaster.master and
script01.js
styles01.css

The content pages are in

FolderA/FolderB/ContentPage01.aspx
and
FolderA/FolderB/FolderC/ContentPage02.aspx

in MyMaster.master I have so

<link href="styles01.css" type="text/css" rel="Stylesheet" />
<script type="text/javascript" src="script01.js"></script>

Now if I call ContentPage01

I see in the generated source css ref is correct maped to ../styles01.css
but javascript include not, it is script01.js
must be ../script01.ja

The same if I call ContentPage02
I see in the generated source css ref is correct maped to
../../styles01.css
but javascript include not, it is script01.js
must be ../../script01.ja

I can in my design only use relativ pathes no other.
Why is stylesheet include mapped correctly and javascript include is not ?
What to do?

Thank you
Rolf Welskes


Aug 23 '06 #2
Hello Rolf,

I just find another thread in this group discussing on the similar question:

subject: "It's trying to compile my JavaScript?"
The problem here is actually due to the <scripttag which is a special
case. Those normal header items (like <link<style....) can be marked
with "runat=server" so that server-side will parse their url property.
However, adding "runat=server" will not work for <scripttag because
<script runat="server" is used for server-side code block.
For your scenario, a simple way to resolve the URL problem is to embed some
server-side code expression to output the absolute url(from application
root directory). e.g.
===============
..............
<head runat="server">
..........

<script language="javascript" src='<%= ResolveUrl("~/scripts/myscript.js")
%>'></script>
.............
</head>
<body>
===============

the "~/scripts/" path will be resolved by the "Page.ResolveUrl" method and
always put the right path to the "script" subfolder under application's
root directory.

Hope this helps. Please feel free to let me know if you have any other
questions on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

Aug 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

30 posts views Thread by Toni Mcintyre | last post: by
1 post views Thread by Andrew Neiderer | last post: by
9 posts views Thread by Howard | last post: by
21 posts views Thread by hemant.singh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.