I too needed to locate the included javascript file at the application root level for my master page. So I put a public variable that contains the HttpContext.Current.Request.ApplicationPath info in the master page's code behind and used it at the front like the code below in the <header runat="server >.
Code:
<script src="<%=AppRoot%>Scripts/Tools.js" type="text/javascript"></script>
It was working just fine until I put an ajax calendar control in one of my page. Suddenly the page failed with the error below:
"The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). "
Once I removed the entire line using the literal tag, it is working again.
Code:
<asp:Literal ID="ltlJavaScriptsFile" runat="server" />
code behind looks like:
Code:
ltlJavaScriptsFile.Text = "<script src=""" & HttpContext.Current.Request.ApplicationPath & "Scripts/Tools.js"" type=""text/javascript""></script>"
So for some reason the ajax controls doesn't like <%= %> in the <head runat="server"> section. This is under .net 4 with ajax tool kit for .net 4.