views:

131

answers:

2

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?

A: 

You could use a web resource

Joel Coehoorn
+1  A: 

I'd recommend using the RegisterClientScriptResource utility. You can certainly do this in a user control.

  1. Right click on the JavaScript file and click properties.
  2. Set Build Action to Embedded Resource
  3. Modify the code below and add it to your user control.
Page.ClientScript.RegisterClientScriptResource(typeof(CurrentTypeHere), "Your.Namespace.Class.Folder.File.js");
Ian Robinson