views:

33

answers:

4

Hi.

Is there any reason why registering a javascript file from the head tags of an ASP.NET master page wouldn't work? For example, I have the following (plus many other) file referece:

<script type="text/javascript" src="/js/jquery/jquery-1.4.2.min.js"></script>

but jquery (and every other JS reference) doesn't work when the page loads.

Any thoughts? Thanks.

+2  A: 

The src attribute is relative, try

<script type="text/javascript" src="/js/jquery/jquery-1.4.2.min.js"></script>

and see if that fixes your problem

phsr
Good catch but that wasn't it (I had that before but must have removed the "/" when I was playing with code or cutting and pasting). Any other ideas?
Code Sherpa
A: 

The masterpage can have script resources just like a normal HTML page; you'll probably want to check the problem with an HTTP debugger like FireBug or Fiddler2, if phsr is correct you'll see the requests failing with an ErrorCode.

STW
+1  A: 

If that doesn't work, you can try this:

<script type="text/javascript" src="<%# ResolveUrl("~/js/jquery/jquery-1.4.2.min.js") %>"></script>

and in your Page Load handler in the master page add this code:

Page.Header.DataBind();
jaltiere
Thanks. Page.Header.DeataBind() throws and object reference exception.
Code Sherpa
Sorry, needed head runat="server". Made your suggested changes but the original problem remains...
Code Sherpa
Does your js folder actually sit on the web root? Are you experiencing this in the dev server from Visual Studio or after deploying? (or both?)
jaltiere
A: 

Using master pages will not affect the loading of JavaScript files. Your problem is either the location of the file or the script tag is formatted incorrectly.

bbarnhart