problem with relative path to .js file in ASP.net ScriptManager
I'm working with an ASP.net web application.
I've written a user control called LocationSelector
that has its own Javascript in an external .js file. In order to load that file, I use the following line of code:
ScriptManager.RegisterClientScriptInclude(this, typeof(LocationSelector), Guid.NewGuid().ToString(), "Controls/LocationSelector.js");
The problem is with "Controls/LocationSelector.js"
. As long as the page that uses the control is in the root directory of the application, everything works. However, as soon as I try to put this control in a page开发者_Go百科 in a subdirectory, it can't load the Javascript file.
How can I fix this?
Haven't tested it, but off the top of my head I would say you need something along the lines of this:
ScriptManager.RegisterClientScriptInclude(this, typeof(LocationSelector), Guid.NewGuid().ToString(), Page.ResolveClientUrl("~/Controls/LocationSelector.js"));
精彩评论