473,770 Members | 6,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2390
/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
3538
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 our file system set up below. Now, in an aspx page, we set as the "src" of our images something like "../images/animage.jpg". If the current actual url in the browser is something like http://server/webapp/(someSessionID)/forms/form1.aspx
21
2969
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 updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not impossible for a single client to request 100 plus pages in one session - as each page is requested it is...
14
2406
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 standard ASPX page with minor modifications to it. All of my pages inherit from a "BasePage.cs" class, that handles common things like getting the user's information out of the session, determines if a page should or should not be password...
20
2428
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 include files to change the layout. When I came to ASP.NET, I used user controls to do a similar thing. I have just been looking at master pages, and it looks like they do the same thing. If so, is there any advantage in using them over the...
2
1674
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. <head runat="server" />). I am using themes and a single Master Page for the application, with the theme being set globally in the web.config file <page theme="xxx" /> is, off the top of my head, the markup, though don't quote me on that. ;-)
9
2143
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 tags and properties are used in a page without a masterpage. Does anyone shares this exprerience with me or does anyone knows an answer? For the time being, I copy-pased the headings in my masterpage to the clield pages.
3
2654
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 real problems with the ASP side of things. Timeline of events is as follows: 1) Added IIS (via Add/Remove Windows Components) on WinXP Pro machine (6
0
1039
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 Images from Master pages cannot be seen. However, the aspx pages in the subfolders can be seen. In my masterpage, I use the table Background image and set the url as ../Images/myim.jpg . But when I change using the Image button ,the images...
0
2752
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 & JS files using the code behind of the content page, my buttons aren't rendered and Im not sure why? Here is the code for my content page - Properties.aspx:- <%@ Page Language="C#" AutoEventWireup="true" Title="Properties"...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.