title: Get the ".ascx" path of a User Control
body: <p>Context:</p>
  
  <p>I have created a custom "Script" control that I use in several of my User Controls (these are all loaded via an ASCX path). This Script control provides several interesting features, but I would now like to be able to move the script <em>out</em> of the ASCX markup into the same directory as the ASCX control and then load this markup dynamically. (I cannot use normal <code>&lt;script&gt;</code> tags because the Script control creates a special binding context such that it can be accessed through a clean API.)</p>
  
  <p>That, currently my Script control is used like (the <code>&lt;script&gt;</code> elements inside are consumed by the Script control and should not be confused with the final HTML markup):</p>
  
  <pre><code>&lt;SmartScript runat="server"&gt;
    &lt;script&gt;/* the code here */&lt;/script&gt;
  &lt;/SmartScript&gt;
  </code></pre>
  
  <p>But I would like it to be usable as:</p>
  
  <pre><code>&lt;SmartScript runat="server"&gt;
    &lt;script src="~parent/theCode.js" /&gt;
  &lt;/SmartScript&gt;
  </code></pre>
  
  <p>However, I want "~parent" to be expanded to the <em>filesystem location</em> of the ASCX control so that I can load the file directly and use that as the contents for the rendered script.</p>
  
  <p>That is, <em>given the ASCX-based user control (which can be obtained through the Parent property), how is it possible to determine the system path which houses the ASCX markup file?</em> (And, what caveats should I be aware of?)</p>
  
  <p>Preferably, this would be the complete path as something like <code>~/_CONTROLTEMPLATES/prj/ctrl.ascx"</code> still leaves another layer of redirect (what does the <code>~</code> mean here?) to work through.</p>
  
  <p>(The application runs with enough trust to read from the filesystem, and I am avoiding embedded resources so I can push Layout changes without needing to push the DLLs and restart the IIS workers.)</p>