473,322 Members | 1,610 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,322 software developers and data experts.

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.close();
}

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

Thank you.
Nov 23 '05 #1
8 1967
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.ApplicationPath%>/scripts/close.js"

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Flip" <ph******@hotmail.com[remove]> wrote in message
news:uB**************@tk2msftngp13.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.close();
}

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.ApplicationPath%>/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.com> wrote in message
news:eq**************@TK2MSFTNGP11.phx.gbl...
src="<%=REquest.ApplicationPath%>/scripts/close.js"

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

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

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:e0*************@tk2msftngp13.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.com> wrote in message
news:eq**************@TK2MSFTNGP11.phx.gbl...
src="<%=REquest.ApplicationPath%>/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="Javascript"
type="text/javascript"
src="<%=Request.ApplicationPath()%>/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.ApplicationPath %>/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 = "ExternalJavaScriptReference";
String url = Request.ApplicationPath + "/Scripts/scripts.js";

// Instantiate ClientScriptManager object
ClientScriptManager cs = Page.ClientScript;

// Do not register if this instance of the key is already
registered.
if (!cs.IsClientScriptIncludeRegistered(key))
{
cs.RegisterClientScriptInclude(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******@hotmail.com[remove]> wrote in message
news:ud**************@tk2msftngp13.phx.gbl...
SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
with quotes?

Something like this.
<script
language="Javascript"
type="text/javascript"
src="<%=Request.ApplicationPath()%>/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 HtmlGenericControl script;

load
script.Attributes["src"] = Request.ApplicationPath +
script.Attributes["src"]

or something

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

<head runat="server">
<script src="<%= Request.ApplicationPath %>/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 = "ExternalJavaScriptReference";
String url = Request.ApplicationPath + "/Scripts/scripts.js";

// Instantiate ClientScriptManager object
ClientScriptManager cs = Page.ClientScript;

// Do not register if this instance of the key is already
registered.
if (!cs.IsClientScriptIncludeRegistered(key))
{
cs.RegisterClientScriptInclude(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******@hotmail.com[remove]> wrote in message
news:ud**************@tk2msftngp13.phx.gbl...
SHOOT! :> Hit the send button prematurely. :< Did you surround your <%=
with quotes?

Something like this.
<script
language="Javascript"
type="text/javascript"
src="<%=Request.ApplicationPath()%>/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
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...
7
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...
8
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...
0
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
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...
2
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...
8
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...
0
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...
5
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.