Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > master pages using JS from external file?

Reply
Thread Tools

master pages using JS from external file?

 
 
Flip
Guest
Posts: n/a
 
      11-22-2005
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.


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      11-22-2005
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" <(E-Mail Removed)[remove]> wrote in message
news:(E-Mail Removed)...
>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.
>



 
Reply With Quote
 
 
 
 
Flip
Guest
Posts: n/a
 
      11-22-2005
> 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! :>


 
Reply With Quote
 
Flip
Guest
Posts: n/a
 
      11-23-2005
> src="<%=REquest.ApplicationPath%>/scripts/close.js"
YAHOO! That worked! Beautiful and thank you! :>


 
Reply With Quote
 
clintonG
Guest
Posts: n/a
 
      11-23-2005
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" <!REMOVE_ME!(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> src="<%=REquest.ApplicationPath%>/scripts/close.js"

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



 
Reply With Quote
 
Flip
Guest
Posts: n/a
 
      11-23-2005
Did you surround the outside with?





"clintonG" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <!REMOVE_ME!(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>> src="<%=REquest.ApplicationPath%>/scripts/close.js"

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

>
>



 
Reply With Quote
 
Flip
Guest
Posts: n/a
 
      11-23-2005
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.


 
Reply With Quote
 
clintonG
Guest
Posts: n/a
 
      11-24-2005
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" <(E-Mail Removed)[remove]> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      11-24-2005
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)[remove]> wrote in message
> news:(E-Mail Removed)...
>> 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.
>>

>
>



 
Reply With Quote
 
vkona vkona is offline
Junior Member
Join Date: Jul 2007
Posts: 1
 
      07-31-2007
the javascript function from external file is firing when i kept this

<script type='text/javascript' src="<%=Request.ApplicationPath%>/presentationLayer/JSFiles/CalendarControl.js" language='javascript' />


path in master page, but all the post back events (like button_click) are not working.

When that is removed all the events are working fine.
is there any problem?

is there any solution to make work both.

 

Last edited by vkona; 07-31-2007 at 10:13 AM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using update panel with master & nested master pages katmagic ASP .Net 0 12-26-2008 07:41 PM
Using Master Pages and Base Pages =?Utf-8?B?RG9u?= ASP .Net 1 09-12-2006 01:32 PM
Cross Page Post Back When Using Mixture of Master Pages and Non-Master Pages Jason@webbit.com ASP .Net 1 05-16-2006 02:00 PM
using external css with master pages Glenn ASP .Net 0 05-10-2006 01:58 PM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments