title: ScriptManager.RegisterClientScriptInclude does not work in UpdatePanel
body: <p>I've read through the net but haven't found a solution to the following problem. I have this example page (_ScriptManager.aspx) with a <code>ScriptManager</code>, an <code>UpdatePanel</code>, a <code>MultiView</code> with two <code>Views</code> and two <code>LinkButtons</code> two switch between the views. The second view contains some functionality which I want to load a JavaScript file for (_ScriptManager.js).</p>
  
  <p>Since I don't know whether the user will ever visit view 2 I don't want to include the javascript file statically on for every request. I only want to load it if and when I need it. So I need to include the script file during an asynchronous postback which is what I use <code>ScriptManager.RegisterClientScriptInclude</code> for. The pain is: it does not work. The script include is somehow not executed on the client so that the javascript functions inside cannot be used. Even worse, the script block I register in <code>ScriptManager.RegisterStartupScript</code> does not get executed in this case! This is all very irritating. The interesting thing is that the include script and the script block do get sent to the client with the async postback (Fiddler is my friend :-)) and the script file is also loaded. But then the javascript somehow seems to break...</p>
  
  <p>Does anyone have a clue or know of a reported bug?</p>
  
  <p><strong>_ScriptManager.aspx</strong>:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="_ScriptManager.aspx.cs" Inherits="Frontend.Web._Tests.ScriptManagerTest" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
      &lt;asp:ScriptManager runat="server" ID="scm"&gt;&lt;/asp:ScriptManager&gt;
      &lt;asp:Label runat="server" ID="lbOut"&gt;Outside of UpdatePanel&lt;/asp:Label&gt;
    &lt;div style="border: solid 1px red;"&gt;
        &lt;asp:UpdatePanel runat="server" ID="up" UpdateMode="Conditional"&gt;
          &lt;ContentTemplate&gt;
            &lt;div&gt;
              &lt;asp:LinkButton runat="server" ID="btnFirst"&gt;Show view 1&lt;/asp:LinkButton&gt;
              &lt;asp:LinkButton runat="server" ID="btnSecond"&gt;Show view 2&lt;/asp:LinkButton&gt;
            &lt;/div&gt;
            &lt;div&gt;
              &lt;asp:MultiView runat="server" ID="mv"&gt;
                &lt;asp:View runat="server" ID="vw1"&gt;First view - static content&lt;/asp:View&gt;
                &lt;asp:View runat="server" ID="vw2"&gt;
                  Second view - dynamically loaded content (between dashes): 
                  &lt;div&gt;#&lt;span id="divDyn"&gt;&lt;/span&gt;#&lt;/div&gt;
                &lt;/asp:View&gt;
              &lt;/asp:MultiView&gt;
            &lt;/div&gt;
          &lt;/ContentTemplate&gt;
        &lt;/asp:UpdatePanel&gt;
    &lt;/div&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>_ScriptManager.js</strong> (here I just add some dynamic content to the span with id=divDyn):</p>
  
  <pre><code>function dynamic() {
    alert('dynamic');
    $('#divDyn').text('Dynamic!');
  }
  </code></pre>
  
  <p><strong>_ScriptManager.aspx.cs</strong> code-behind:</p>
  
  <pre><code>public partial class ScriptManagerTest : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          btnFirst.Click += delegate { mv.SetActiveView(vw1); };
          btnSecond.Click += delegate { mv.SetActiveView(vw2); };
  
          if (!IsPostBack)
          {
              // Test 1: does not work
              mv.SetActiveView(vw1);
  
              // Test 2: works, because required script is loaded on initial page request
              //mv.SetActiveView(vw2);
          }
      }
  
      protected override void OnPreRender(EventArgs e)
      {
          base.OnPreRender(e);
  
          if (mv.GetActiveView() == vw2)
          {
              // Not calling the RegisterClientScriptInclude
              // makes the alert work in both cases, but this is
              // what it's all about: including script only when
              // needed!
              ScriptManager.RegisterClientScriptInclude(
                  Page, Page.GetType(), "include-js",
                  ResolveClientUrl("~/ScriptManager.js"));
              ScriptManager.RegisterStartupScript(
                  this, GetType(), "call-dynamic",
                  "alert('hi there'); dynamic();", true);    
          }
      }
  }
  </code></pre>