471,571 Members | 1,083 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,571 software developers and data experts.

Use Java Script File with Asp.Net page that uses a Master page.

I'm using some Java Script I found that supports a 'back' button on my
ASP.Net page. The Asp.Net page uses a Master page. I thought I'd put the
Java Script in a Java Script file [.js]. The thought was that I could use
this script in other pages. So I put a reference to the script file in the
<head tag of the Master page. But that does not work because the <head tag
of the Master page also contains a 'runat=server' statement. And only one
<head statement is allowed.

Next I tried referencing the script file in the Asp.Net page and I get an
'Error on page' message at run time when I click the 'back' button. If I put
the script in the asp.net page then it works fine.

Is there a way to reference a script file in an asp.net page that uses a
master page?

Cheers,
Larry Rebich
Dec 1 '06 #1
1 3029
Hello Larry,

You should be able to place a reference to a .js file in the masterpage.
Something like the following:

<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<head runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" type="text/css" href="~/stylesheet.css"/>
<script type="text/javascript" src="~/jscript.js"></script>
</head>

Not exactly sure why it isn't working for you. Scott over at OdeToCode.com
has written a nice article on MasterPages: Tips, Trickes,and Traps. Well
worth looking into if you haven't already:
http://www.odetocode.com/Articles/450.aspx.

--
cheers - brians
http://www.limbertech.com
"Larry Rebich" wrote:
I'm using some Java Script I found that supports a 'back' button on my
ASP.Net page. The Asp.Net page uses a Master page. I thought I'd put the
Java Script in a Java Script file [.js]. The thought was that I could use
this script in other pages. So I put a reference to the script file in the
<head tag of the Master page. But that does not work because the <head tag
of the Master page also contains a 'runat=server' statement. And only one
<head statement is allowed.

Next I tried referencing the script file in the Asp.Net page and I get an
'Error on page' message at run time when I click the 'back' button. If I put
the script in the asp.net page then it works fine.

Is there a way to reference a script file in an asp.net page that uses a
master page?

Cheers,
Larry Rebich
Dec 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mark Olbert | last post: by
8 posts views Thread by dbaplusplus | last post: by
7 posts views Thread by pbd22 | last post: by
2 posts views Thread by =?Utf-8?B?REo=?= | last post: by
2 posts views Thread by Jay | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

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.