Reputation: 11817
The folder structure we have is something like this:
ParentFolder
HostPage1.aspx
UserControlsFolder
UserControl.ascx
AnotherFolder
HostPage2.aspx
UserControl.ascx is used in both HostPage1.aspx AND HostPage2.aspx
I am including an external JS file in the ASCX and the path needs to be relative to the Page. Since I have pages in different hierarchy structure, how would I conditionally change the path based on whether its being used in HostPage1 or HostPage2?
If it can be avoided, I would not want to add the JS include directive in the hostpages
EDIT Can I use web resource in a user control?
Upvotes: 0
Views: 351
Reputation: 16944
I'd recommend using the RegisterClientScriptResource
utility. You can certainly do this in a user control.
Page.ClientScript.RegisterClientScriptResource(typeof(CurrentTypeHere), "Your.Namespace.Class.Folder.File.js");
Upvotes: 1