|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
java <script> include in Master pages - src is not mappedI 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 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 Show quoteHide quote "Rolf Welskes" <rolf@nospam.nospam> wrote in message news:uOWotuuxGHA.1292@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 > > 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 <script> tag 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 <script> tag 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
Other interesting topics
Custom Errors Not Working
January 2006 version of EntLib samples, etc? Is Visual Studio 2005 complict with Visual Studio 2003 Software Marketing Website with Forum and Knowledge Base Enum returns wrong default values in a web service Running code before Page_Error Problems with app_offline.htm not showing after app uninstall can you control where response.writes? publish web site loses context disabling session state in iis vs web.config |
|||||||||||||||||||||||