master pages using JS from external file?

  • Thread starter Thread starter Flip
  • Start date Start date
F

Flip

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.
 
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
 
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! :>
 
src="<%=REquest.ApplicationPath%>/scripts/close.js"
YAHOO! That worked! Beautiful and thank you! :>
 
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
 
Did you surround the outside with?





clintonG said:
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
 
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.
 
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/
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top