title: ASP.NET Register Script After Partial Page Postback (UpdatePanel)
body: <p>I have a simple form (textbox, submit button) which is wrapped in an update panel.</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="ReplyUpdatePanel" UpdateMode="Conditional" runat="server"&gt;
      &lt;ContentTemplate&gt;
         &lt;asp:Textbox id="ReplyTextBox" runat="server"/&gt;
         &lt;asp:Button id="SubmitButton" OnClick="SubmitButton_Click" runat="server"/&gt;
      &lt;ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>So, when i click the button, the server-side click event is fired (SubmitButton_Click), stuff happens to the db, and the page is re-rendered (asynchronously).</p>
  
  <p>Here's my issue - i need to execute some JavaScript after all the "stuff happens to the db".</p>
  
  <p>In other words, i need to create some JavaScript whose data/parameters are based on server-side logic.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>Page.RegisterStartupScript
  </code></pre>
  
  <p>and this</p>
  
  <pre><code>ScriptManager.RegisterStartupScript
  </code></pre>
  
  <p>Neither work (nothing happens).</p>
  
  <p>Now i now i can hook into the <code>.add_pageLoaded</code> function using the client-side AJAX libary (to execute client-side scripts once partial update is complete), but the problem is i need data from the server that is created on the button click event.</p>
  
  <p>Ie:</p>
  
  <pre><code>Sys.Application.add_init(function () {
                  Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (sender, args) {
                      var panels = args.get_panelsUpdated();
                      for (var i = 0; i &lt; panels.length; i++) {
                          // check panels[i].id and do something
                      }
                  });
              });
  </code></pre>
  
  <p>The only "hack" i can think of at the moment is to do the above, but call a web service, getting all the data again then executing my script. I say "hack" because i shouldnt need to do an asynchronous postback, hook into the after-partial-postback event handler then call the server again just to get the info that was previously posted.</p>
  
  <p>Seems like a common problem. And no, i cannot remove the UpdatePanel (even though i would love to), don't want to waste time arguing why. </p>
  
  <p>Any non-hacky ideas?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Clarification on the data i need sent to script:</p>
  
  <p>I type some text in the textbox, click submit, then the server creates a database record and returns an object, which has properties like ID, Name, URL, Blah, etc. These are the values that the script requires. </p>
  
  <p>So if i were to call a web service from the client-code, in order to get the values that were just created, i would need to do some hacks (get last record modified that has the value of the textbox). Not ideal, and neither is two AJAX calls for one form post. (update panel postback, then web service call).</p>