开发者

problem with relative path to .js file in ASP.net ScriptManager

开发者 https://www.devze.com 2023-02-16 05:42 出处:网络
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

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")); 
0

精彩评论

暂无评论...
验证码 换一张
取 消