registering a javascript file from a master page

那年仲夏 提交于 2019-12-12 01:22:18

问题


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.


回答1:


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();



回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/3151632/registering-a-javascript-file-from-a-master-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!