Today a colleague of mine asked me if I knew how to fix his JavaScript include problem. While I used to know the answer in the amount of time it took me to try and recall it he had found it on his own. What can I say, he is a smart guy.
Regardless, here is that solution for everyone's reference:
The Problem
Lets say you have a situation where you have a master page with many other pages in various places such as the root path and sub-folders using it.
Now lets also add that this mater page has a reference to a common script include such as a JavaScript .JS file. The problem you will then run into is that just having this code wont find the common.js file once you go one level or more deep into your sub-folders
Broken Code:
<script language="javascript" type="text/javascript" src="/Common.js"></script>
Instead you need something that will dynamically change the path of the script no matter where you go, and this is the solution:
Solution:
<script language="javascript" type="text/javascript" src="<% =ResolveUrl("~/Common.js") %>"></script>
This is not the only solution
There is more then one way to fry a potato (or something like that) but this is one approach that works. If you have other solutions please feel free to respond to this thread and post them.


