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

L

Larry Rebich

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
 
G

Guest

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.
 

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

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top