Preferred way to include relative reference to JavaScript in VS 2008 nested Masterpage

心不动则不痛 提交于 2019-11-30 13:57:27

Use the ScriptManager server control:

  <asp:ScriptManager ID="myScriptManager" runat="server">
    <Scripts>
      <asp:ScriptReference Path = "~/javascript/actions.js" /> 
      <asp:ScriptReference Path = "~/javascript/jquery/jquery-1.2.6.min.js" />
    </Scripts>
  </asp:ScriptManager>
Shawn Miller

Have you tried:

<script type="text/javascript" src='<%= Page.ResolveClientUrl("~/javascript/actions.js") %>'></script>

As per ScottGu,

One tip to take advantage of is the relative path fix-up support provided by the head runat="server" control. You can use this within Master Pages to easily reference a .CSS stylesheet that is re-used across the entire project (regardless of whether the project is root referenced or a sub-application):

The path fix-up feature of the head control will then take the relative .CSS stylesheet path and correctly output the absolute path to the stylesheet at runtime regardless of whether it is a root referenced web-site or part of a sub-application.

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