473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems with .js files using Master Pages

Hi, all:

I have a problem with the inclusion of .js files in mu .aspx pages when
using Master Pages. I try to explain it. If I make a web project without
master pages I simply put in the head tag on each page the reference to the
..js file I want to use. Because I want client side includes I make the
reference with <script> tag, for example:
<head runat=server>
<script src="/javascript/test.js" />
</head>

But, If I try to make the same project using Master Pages this don´t work. I
suppose I have to put the references to .js files in the master pages. So I
put the code listed before in the master page <head> tag, create an .aspx
page, use a function of the .js file and it doesn´t work. But, If I put this
path ( "javascript/test.js") instead of this ( "/javascript/test.js") it
works fine (note the difference in the first backslash). I need to use the
first one, with the first backslash. Anyone knows which is the problem?

Any help would be appreciated.
Mar 30 '06 #1
8 2366
/javascript/test.js should work OK, what is the difference in the HTML output
between the two versions? If you HTML is getting rendered exactly as you
wanted, what happens if you put srcript tags ina standard HTML page on the
server, does it do the same thing? If so perhaps it's a server configuration
issue rather than an ASP.net thing.

"otto" wrote:
Hi, all:

I have a problem with the inclusion of .js files in mu .aspx pages when
using Master Pages. I try to explain it. If I make a web project without
master pages I simply put in the head tag on each page the reference to the
.js file I want to use. Because I want client side includes I make the
reference with <script> tag, for example:
<head runat=server>
<script src="/javascript/test.js" />
</head>

But, If I try to make the same project using Master Pages this don´t work. I
suppose I have to put the references to .js files in the master pages. So I
put the code listed before in the master page <head> tag, create an .aspx
page, use a function of the .js file and it doesn´t work. But, If I put this
path ( "javascript/test.js") instead of this ( "/javascript/test.js") it
works fine (note the difference in the first backslash). I need to use the
first one, with the first backslash. Anyone knows which is the problem?

Any help would be appreciated.

Mar 30 '06 #2
Hi, clickon:

the html rendered is exactly the same except for the first backslash. If i
use "javascript/test.js" or "./javascript/test.js" it works fine. With
"/javascript/test.js" it doesn´t works. And this only happens with master
pages. I´m confused... :)
"clickon" wrote:
/javascript/test.js should work OK, what is the difference in the HTML output
between the two versions? If you HTML is getting rendered exactly as you
wanted, what happens if you put srcript tags ina standard HTML page on the
server, does it do the same thing? If so perhaps it's a server configuration
issue rather than an ASP.net thing.

"otto" wrote:
Hi, all:

I have a problem with the inclusion of .js files in mu .aspx pages when
using Master Pages. I try to explain it. If I make a web project without
master pages I simply put in the head tag on each page the reference to the
.js file I want to use. Because I want client side includes I make the
reference with <script> tag, for example:
<head runat=server>
<script src="/javascript/test.js" />
</head>

But, If I try to make the same project using Master Pages this don´t work. I
suppose I have to put the references to .js files in the master pages. So I
put the code listed before in the master page <head> tag, create an .aspx
page, use a function of the .js file and it doesn´t work. But, If I put this
path ( "javascript/test.js") instead of this ( "/javascript/test.js") it
works fine (note the difference in the first backslash). I need to use the
first one, with the first backslash. Anyone knows which is the problem?

Any help would be appreciated.

Mar 30 '06 #3
Have you tried <script src="~/javascript/test.js" /> ?

The tilde will map to the root of the virtual directory if your head is
running at server.

Mar 30 '06 #4
Well, the problem is that I need the path begins with only a backslash. Why?
Because in production the application static content (.css, .js, .gif, ...)
will be under Apache, and this is the only way for reference them. For
example, we will have a virtual directory in Apche for all images called
"IMAGES" and we have to reference it from the code as "/IMAGES/image_name".
Do uoy understand what I mean?

Thanks a lot for your interest!

"Flinky Wisty Pomm" wrote:
Have you tried <script src="~/javascript/test.js" /> ?

The tilde will map to the root of the virtual directory if your head is
running at server.

Mar 30 '06 #5
I do understand, the initial forward slash (backslash is \) refers to
the root of the application - if your head is running at the server and
you refer to your files with ~/SomeDir the output should, in your case,
just be /SomeDir. Or am I missing something?

Mar 30 '06 #6
Definatley don't put a tilde in a url if you are using apache as you may get
vewry strange results. A tilde in apaches on *nix refers to a users home
directory e.g. http://www.somedomeian.com/~FredB may well try to load files
from fredb's home folder.

To be clear, on the same server, if you had three identical files as below

if you had a static HTML file that contained

<script src="/javascript/test.js" />

in the head section and that file had a function called somefunction() in it
then a call to somefunction() would work OK.

If you had and ASPX file that contained

<script src="/javascript/test.js" />

in the head section and that file had a function called somefunction() in it
then a call to somefunction() would work OK.

But...

If you have a masterpage that contained

<script src="/javascript/test.js" />

in the head section and that file had a function called somefunction() in it
then a call to somefunction() within the content section of the child ASPX
page the it would not work.

But in each case the rendered HTML would be the same.

If the above is true then i am at a loss as well, if i have missed something
please point out where i have gone wrong.

"otto" wrote:
Well, the problem is that I need the path begins with only a backslash. Why?
Because in production the application static content (.css, .js, .gif, ...)
will be under Apache, and this is the only way for reference them. For
example, we will have a virtual directory in Apche for all images called
"IMAGES" and we have to reference it from the code as "/IMAGES/image_name".
Do uoy understand what I mean?

Thanks a lot for your interest!

"Flinky Wisty Pomm" wrote:
Have you tried <script src="~/javascript/test.js" /> ?

The tilde will map to the root of the virtual directory if your head is
running at server.

Mar 30 '06 #7
Hi clickon:

you´re completely right. That´s exactly the problem! I didn´t find a
solution so we report the problem to Microsoft.

We´re hoping their answers! I let you know! And Thanks a lot again!

"clickon" wrote:
Definatley don't put a tilde in a url if you are using apache as you may get
vewry strange results. A tilde in apaches on *nix refers to a users home
directory e.g. http://www.somedomeian.com/~FredB may well try to load files
from fredb's home folder.

To be clear, on the same server, if you had three identical files as below

if you had a static HTML file that contained

<script src="/javascript/test.js" />

in the head section and that file had a function called somefunction() in it
then a call to somefunction() would work OK.

If you had and ASPX file that contained

<script src="/javascript/test.js" />

in the head section and that file had a function called somefunction() in it
then a call to somefunction() would work OK.

But...

If you have a masterpage that contained

<script src="/javascript/test.js" />

in the head section and that file had a function called somefunction() in it
then a call to somefunction() within the content section of the child ASPX
page the it would not work.

But in each case the rendered HTML would be the same.

If the above is true then i am at a loss as well, if i have missed something
please point out where i have gone wrong.

"otto" wrote:
Well, the problem is that I need the path begins with only a backslash. Why?
Because in production the application static content (.css, .js, .gif, ...)
will be under Apache, and this is the only way for reference them. For
example, we will have a virtual directory in Apche for all images called
"IMAGES" and we have to reference it from the code as "/IMAGES/image_name".
Do uoy understand what I mean?

Thanks a lot for your interest!

"Flinky Wisty Pomm" wrote:
Have you tried <script src="~/javascript/test.js" /> ?

The tilde will map to the root of the virtual directory if your head is
running at server.

Mar 30 '06 #8
I'd just remove the runat=server from your <head> tag.

Putting the runat=server in your <head> tag will add the ../ to your
<script src> tags.

So when you use /javascript/test.js you should actually get an error
under IIS becuase Asp.Net will make it ..//javascript/test.js or
.../../javascript/test.js or some crazy nonsense.

I'm a bit confused though. Sounds like you are testing on IIS but will
go live under Apache (using modmono?).

Note that if you remove the runat=sever from the <head> you will also
probably have to reference any CSS in your head section as opposed to
using the StyleSheetTheme attribute in your page declaration. (did that
even makes sense?....)

otto wrote:
Hi, all:

I have a problem with the inclusion of .js files in mu .aspx pages when
using Master Pages. I try to explain it. If I make a web project without
master pages I simply put in the head tag on each page the reference to the
.js file I want to use. Because I want client side includes I make the
reference with <script> tag, for example:
<head runat=server>
<script src="/javascript/test.js" />
</head>

But, If I try to make the same project using Master Pages this don´t work. I
suppose I have to put the references to .js files in the master pages. SoI
put the code listed before in the master page <head> tag, create an .aspx
page, use a function of the .js file and it doesn´t work. But, If I putthis
path ( "javascript/test.js") instead of this ( "/javascript/test.js") it
works fine (note the difference in the first backslash). I need to use the
first one, with the first backslash. Anyone knows which is the problem?

Any help would be appreciated.


Apr 1 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Scott | last post by:
Hello, we are having problems displaying non-aspx files (images, style sheets) since we have upgraded to the 1.1 framework when using a cookieless session (sessionID in the url). Check out...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
14
by: multiformity | last post by:
So I have been working on an opensource project for a while, and decided to really try to make it look better after focusing on the functionality most of this time. Up to now, I have simply used a...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
2
by: Christophe Peillet | last post by:
I have an application that works fine on localhost, but when it is deployed to a production server, I get the following error: Using themed css files requires a header control on the page. (e.g....
9
by: RBM007 | last post by:
Hello, I have created some pages in the (old) Atlas pages and migrated to AJAX version. After the update I noticed that any page containing ASP.NET AJAX won't compile anymore. Even if the same...
3
by: Newbie | last post by:
Hi All Trying to create a mini-ASP web dev with a couple of PCs at school. When the teachers are happy with the site on the LAN then going to upload it to the school site. Problem is having...
0
by: saukpatthanshwe | last post by:
In myproject, there are three Master Pages under Master Folder. And I have many subfolders storing aspx pages which use that MasterPages. The Problem is that aspx pages in the root directory , the...
0
by: dixonjm | last post by:
Hi, I have a master page & various pages that will use this master page. Each content page will have a CSS & JS file which will be named the same as the content page. When I try to load the CSS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.