473,796 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

master pages using JS from external file?

I have a website that's using Master pages (very cool). But when I put JS
on there (to close the browser for example) coming from an external file,
when I navigate away from the first page, the JS no longer works. Can
someone explain why this is happening? How can I fix this so that the JS is
generic enough to work on every aspx to be included in the external JS file?

The external JS file looks like this right now

function closePage()
{
this.window.clo se();
}

I've tried it without the this, but then nothing seemed to work.

Thank you.
Nov 23 '05 #1
8 1993
Is the problem just pathing?

like, you have src="scripts/close.js"

and it works when ur in
/index.aspx
but not when ur in
/user/blah.aspx ?

if so, just stick something like

src="<%=REquest .ApplicationPat h%>/scripts/close.js"

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Flip" <ph******@hotma il.com[remove]> wrote in message
news:uB******** ******@tk2msftn gp13.phx.gbl...
I have a website that's using Master pages (very cool). But when I put JS
on there (to close the browser for example) coming from an external file,
when I navigate away from the first page, the JS no longer works. Can
someone explain why this is happening? How can I fix this so that the JS
is generic enough to work on every aspx to be included in the external JS
file?

The external JS file looks like this right now

function closePage()
{
this.window.clo se();
}

I've tried it without the this, but then nothing seemed to work.

Thank you.

Nov 23 '05 #2
> Is the problem just pathing?
hhhmm that might be it? So simple, and I missed it! :< I just assumed that
I wasn't getting any errors, and that it worked from the root, all was ok.
But now that you mention it, I think you're right, the problem is with the
sub paths only! DOH!

Thank you very much! :>
Nov 23 '05 #3
> src="<%=REquest .ApplicationPat h%>/scripts/close.js"
YAHOO! That worked! Beautiful and thank you! :>
Nov 23 '05 #4
Doesn't work for me when used in the Master...
The Controls collection cannot be modified because the control contains code
blocks (i.e. <% ... %>).

<%= Clinton Gallagher

"Flip" <!R************ *****@hotmail.c om> wrote in message
news:eq******** ******@TK2MSFTN GP11.phx.gbl...
src="<%=REquest .ApplicationPat h%>/scripts/close.js"

YAHOO! That worked! Beautiful and thank you! :>

Nov 23 '05 #5
Did you surround the outside with?

"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com > wrote in message
news:e0******** *****@tk2msftng p13.phx.gbl...
Doesn't work for me when used in the Master...
The Controls collection cannot be modified because the control contains
code blocks (i.e. <% ... %>).

<%= Clinton Gallagher

"Flip" <!R************ *****@hotmail.c om> wrote in message
news:eq******** ******@TK2MSFTN GP11.phx.gbl...
src="<%=REquest .ApplicationPat h%>/scripts/close.js"

YAHOO! That worked! Beautiful and thank you! :>


Nov 23 '05 #6
SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
with quotes?

Something like this.
<script
language="Javas cript"
type="text/javascript"
src="<%=Request .ApplicationPat h()%>/ButtonHandlers. js">
</script>

I'm going from memory, but I HTH. Good luck.
Nov 23 '05 #7
Here's what I used...

<head runat="server">
<script src="<%= Request.Applica tionPath %>/Scripts/scripts.js"
type="text/JavaScript"></script>
</head>

That raises this error...
The Controls collection cannot be modified because the control contains code
blocks (i.e. <% ... %>).

Catch-22...
This HTML web server control -- <head runat="server"> -- is raising the
exception and we can not remove runat="server" from the head element when
using 2.0 Themes. Thus, we can not use ServerVariables with expressions to
dynamically assign a path or we have to remove runat="server" and stop using
Themes. Nice choice.

A Page_Load Solution...

#region Write External JavaScript Library <script> Declaration...

// Dynamically assign path to external Javascript library src
attribute
// by writing <script...></script> into the body of the page
// obviating the need for <script...></script> to be located in
the
// <head> element which imposes conflict when using Themes.

// Define an arbitrary but unique name to use as a key
String key = "ExternalJavaSc riptReference";
String url = Request.Applica tionPath + "/Scripts/scripts.js";

// Instantiate ClientScriptMan ager object
ClientScriptMan ager cs = Page.ClientScri pt;

// Do not register if this instance of the key is already
registered.
if (!cs.IsClientSc riptIncludeRegi stered(key))
{
cs.RegisterClie ntScriptInclude (key, url);
}
#endregion

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee. com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/


"Flip" <ph******@hotma il.com[remove]> wrote in message
news:ud******** ******@tk2msftn gp13.phx.gbl...
SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
with quotes?

Something like this.
<script
language="Javas cript"
type="text/javascript"
src="<%=Request .ApplicationPat h()%>/ButtonHandlers. js">
</script>

I'm going from memory, but I HTH. Good luck.

Nov 24 '05 #8
you cn simply give you <Script tag a runat="server" and declare the path in
the codebehind of your master page.

protected HtmlGenericCont rol script;

load
script.Attribut es["src"] = Request.Applica tionPath +
script.Attribut es["src"]

or something

karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com > wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Here's what I used...

<head runat="server">
<script src="<%= Request.Applica tionPath %>/Scripts/scripts.js"
type="text/JavaScript"></script>
</head>

That raises this error...
The Controls collection cannot be modified because the control contains
code blocks (i.e. <% ... %>).

Catch-22...
This HTML web server control -- <head runat="server"> -- is raising the
exception and we can not remove runat="server" from the head element when
using 2.0 Themes. Thus, we can not use ServerVariables with expressions to
dynamically assign a path or we have to remove runat="server" and stop
using Themes. Nice choice.

A Page_Load Solution...

#region Write External JavaScript Library <script> Declaration...

// Dynamically assign path to external Javascript library src
attribute
// by writing <script...></script> into the body of the page
// obviating the need for <script...></script> to be located in
the
// <head> element which imposes conflict when using Themes.

// Define an arbitrary but unique name to use as a key
String key = "ExternalJavaSc riptReference";
String url = Request.Applica tionPath + "/Scripts/scripts.js";

// Instantiate ClientScriptMan ager object
ClientScriptMan ager cs = Page.ClientScri pt;

// Do not register if this instance of the key is already
registered.
if (!cs.IsClientSc riptIncludeRegi stered(key))
{
cs.RegisterClie ntScriptInclude (key, url);
}
#endregion

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee. com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/


"Flip" <ph******@hotma il.com[remove]> wrote in message
news:ud******** ******@tk2msftn gp13.phx.gbl...
SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
with quotes?

Something like this.
<script
language="Javas cript"
type="text/javascript"
src="<%=Request .ApplicationPat h()%>/ButtonHandlers. js">
</script>

I'm going from memory, but I HTH. Good luck.


Nov 24 '05 #9

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

Similar topics

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...
7
3509
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme attribute. This works for the content pages, but it doesn't seem able to apply the styles to the top master page even though I did set the master head tag to runat server. Is this by design? If so, what is the best way to apply styles to the top...
8
2392
by: otto | last post by:
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>
0
1243
by: Glenn | last post by:
Hi Can I use external style sheets with Master/content pages in ASP.NET 2 .. As thc ontent page can't define a head tag does this mean i can't define an external style sheet?
2
1483
by: Rob R. Ainscough | last post by:
I'm using a single Master page. I'm having some strange results using Redirects in master pages using relative pathing i.e ~. I'm using Form authentication and whenever I navigate to my Login form (under a different dir called Secure) and then navigate back to my main form under root dir and then try to navigate to another form at the root dir level, it will look for the aspx page under the "Secure" dir rather than my root dir?? ...
2
7030
by: SR | last post by:
I have started a web site using ASP.NET 2.0. I would like to centralize all of my classes in a StyleSheet but I cannot figure out how to link the StyleSheet to a Content Page since there is no header. I tried to put the link tag in the Master page, but the classes are not recognized in the Content Page. How do I use a StyleSheet with the Content Page? TIA
8
6701
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet and also my first true attempt at using master pages. I tried setting up a style sheet with a simple setting to float an image to the right and it had no effect on the image. Then, I tried putting the style code in my ASPX file as such,
0
2120
by: james.mcdonagh | last post by:
Hi I am a newbie using nAnt for .net 2.0. As such I have not come across this bug before, and I would be happy of any help that you may be able to provide. In order to help I have included the nant file which is causing the problem, the object code that is not being built and the error message which is being produced. The weird thing is that VS.net builds without a problem. And the intellisense within the object WorkQueue knows that...
5
12228
by: Joey | last post by:
I have the following in the head section of the ASPX page for my master page: <script language="javascript" type="text/javascript" src="MyCodeFile.js"></script> This includes my external javascript code file for my master page and all subscribing pages. But I ran into a problem. This only works for pages in the root directory of the site. The (relative) path is wrong for pages in other folders on the website.
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
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
10169
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
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
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
5440
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...
1
4115
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
3
2924
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.