My organization is developing an ASP.NET application consisting of a parent WAP project with multiple WAP sub-projects. I ran into a problem loading JavaScript files located in the parent WAP Scripts folder – the sub-project WAPs were not able to load the scripts.
There are two solutions to this problem. One answer is to use a declarative path in the script tag:
- <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/Scripts/MyScript.js")%>"></script>
A second answer is to use a ScriptManager (or ScriptManagerProxy) control:
- <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
- <Scripts>
- <asp:ScriptReference Path="~/Scripts/MyScript.js" />
- </Scripts>
- </asp:ScriptManagerProxy>
Either solution appears to work for any page in the parent or any sub-project WAP. However, the ScriptManager solution is a more reliable way to ensure that all scripts are loaded in the correct sequence.
No comments:
Post a Comment