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

Discussion in 'ASP .Net' started by Larry Rebich, Dec 2, 2006.

  1. Larry Rebich

    Larry Rebich Guest

    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
    Larry Rebich, Dec 2, 2006
    #1
    1. Advertising

  2. 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
    >
    >
    >
    =?Utf-8?B?YnJpYW5zW01DU0Rd?=, Dec 2, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug McCann
    Replies:
    1
    Views:
    993
    William Brogden
    Aug 5, 2004
  2. McGeeky
    Replies:
    7
    Views:
    436
    McGeeky
    May 18, 2006
  3. BillE
    Replies:
    0
    Views:
    449
    BillE
    Nov 8, 2006
  4. Zeba
    Replies:
    1
    Views:
    480
    Mark Rae
    Feb 22, 2007
  5. Replies:
    0
    Views:
    106
Loading...

Share This Page