title: Registering javascript on asynchronous postback
body: <p>I have an asp.net button wrapped inside of an UpdatePanel, and when clicked it does an asynchronous postback and registers some javascript that shows a jquery dialog.</p>
  
  <pre><code>protected void btnAddData(object sender, EventArgs e) {
      StringBuilder jqueryDialog = new StringBuilder();
      jqueryDialog.Append("$(document).ready(function() {");
      jqueryDialog.Append("RefreshData();");
      jqueryDialog.Append("$('#divData').dialog({ modal: false, draggable: true, title: 'Historical Data', width: 700 });");
      jqueryDialog.Append("});");
  
      ScriptManager sm = ScriptManager.GetCurrent(this);
      if (sm != null &amp;&amp; sm.IsInAsyncPostBack) {
          ScriptManager.RegisterClientScriptBlock(
              this, typeof(Page), Guid.NewGuid().ToString(),
              jqueryDialog.ToString(), true);
      }
  }
  </code></pre>
  
  <p>As you can see the javascript first calls a function named RefreshData(), which function exists in my markup as javascript.</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
      if ($) {
          $(document).ready(function () {
              function RefreshData() {
                  alert("Data Refreshed!");
              }
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>However, Firefox is giving an error that says the <strong>RefreshData is not defined</strong>. Does that mean any javascript that I register on an asynchronous postback will be unable to use 
  javascript functions that I have defined in my markup?</p>
  
  <p>Thanks for the help.</p>