By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,526 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,526 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.