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

前端 未结 3 1480
猫巷女王i
猫巷女王i 2021-01-02 14:55

Our base Masterpage has something like the following

  
   

   

        
相关标签:
3条回答
  • 2021-01-02 15:39

    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.

    0 讨论(0)
  • 2021-01-02 15:49

    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>
    
    0 讨论(0)
  • 2021-01-02 15:52

    Have you tried:

    <script type="text/javascript" src='<%= Page.ResolveClientUrl("~/javascript/actions.js") %>'></script>
    
    0 讨论(0)
提交回复
热议问题