title: How to include jQuery in ASP.net page?
body: <p>i have an ASP.net <code>UserControl</code> that requires the containing page to include a reference to jquery.</p>
  
  <p>In the olden days, i would simply have included a reference to jQuery in the containing page:</p>
  
  <pre><code>&lt;HEAD&gt;
     &lt;SCRIPT type="text/javascript" src="Scripts/jquery-1.7.2.min.js"&gt;&lt;/SCRIPT&gt;
  &lt;/HEAD&gt;
  </code></pre>
  
  <p>But my UserControl's dependency on jQuery is an internal implementation detail, that should not be leaking to the outside. How can my userControl dictate that jQuery be included in the final page?</p>
  
  <hr>
  
  <p>Researching this, i find a lot of confused solutions, calling different functions at different times. i hesitate to mention <strong>any</strong> of them, because people might think that any of them are valid. i am hoping for the <strong>correct</strong> answer, not an answer that works.</p>
  
  <p>Different solutions involve calling:</p>
  
  <ul>
  <li><a href="http://www.beansoftware.com/ASP.NET-Tutorials/Using-jQuery-ASP.NET.aspx" rel="nofollow noreferrer">calling <code>this.Page.ClientScript.RegisterClientScriptInclude</code> during <code>Render</code></a></li>
  <li><a href="https://stackoverflow.com/questions/3866511/why-do-i-need-registerstartupscript-for-a-simple-jquery-helloworld-in-asp-net">calling <code>this.Page.ClientScript.RegisterStartupScript</code> during <code>Render</code></a></li>
  <li><a href="http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx" rel="nofollow noreferrer">calling <code>this.Page.ClientScript.RegisterStartupScript</code> during <code>Page_Load</code></a></li>
  <li><a href="http://forums.asp.net/t/1448049.aspx/1" rel="nofollow noreferrer">calling <code>this.Page.ClientScript.RegisterStartupScript</code> during a button click</a></li>
  <li><a href="https://stackoverflow.com/questions/521639/programmatically-adding-javascript-file-to-user-control-in-net">calling <code>Page.Header.Controls.Add(new LiteralControl( { Text = "&lt;script type=\"text/javascript\" src=\"...\"&gt;&lt;/script&gt;";);</code></a></li>
  <li><a href="http://forums.asp.net/t/1366290.aspx/1" rel="nofollow noreferrer">simply including a <code>&lt;SCRIPT&gt;</code> element in your <code>userControl.ascx</code> file</a></li>
  <li><a href="https://stackoverflow.com/questions/3751653/register-javascript-from-within-a-usercontrol-in-asp-net">calling <code>RegisterClientScriptBlock</code> during <code>OnPreRender</code></a></li>
  </ul>
  
  <p>My confusion is centered around:</p>
  
  <ul>
  <li>when would i want to use <code>RegisterClientScriptInclude</code> vs <code>RegisterStartupScript</code>?</li>
  <li>when would i want to call it during <code>Page_Load</code> vs <code>Render</code> vs <code>PreRender</code> vs a button click?</li>
  <li>how do i give <code>RegisterXxxxScriptXxx</code> the path to <code>"Scripts/jquery-1.7.2.min.js"</code>?</li>
  </ul>
  
  <hr>
  
  <p>Short version: How do i convert</p>
  
  <pre><code>&lt;%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
      Inherits="_Default" %&gt;&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head runat="server"&gt;
      &lt;script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>for use in a UserControl:</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="MySuperCoolControl.ascx.cs" Inherits="Controls_MySuperCoolControl" %&gt;
  </code></pre>