title: Difference between RegisterStartupScript and RegisterClientScriptBlock?
body: <p>Is the only difference between the <code>RegisterStartupScript</code> and the <code>RegisterClientScriptBlock</code> is that RegisterStartupScript puts the javascript before the closing <code>&lt;/form&gt;</code> tag of the page and RegisterClientScriptBlock puts it right after the starting <code>&lt;form&gt;</code> tag of the page?  </p>
  
  <p>Also, when would you choose one over the other?  I wrote up a quick sample page where I had an issue and I am not sure the exact reason of why it is happening.  </p>
  
  <h3>Here is the aspx markup:</h3>
  
  <pre class="lang-html prettyprint-override"><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head runat="server"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form id="form1" runat="server"&gt;
              &lt;div&gt;
                  &lt;asp:Label ID="lblDisplayDate" runat="server"
                             Text="Label" /&gt;&lt;br /&gt;
                  &lt;asp:Button ID="btnPostback" runat="server" 
                              Text="Register Startup Script"
                              onclick="btnPostback_Click" /&gt;&lt;br /&gt;
                  &lt;asp:Button ID="btnPostBack2" runat="server" 
                              Text="Register"
                              onclick="btnPostBack2_Click" /&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h3>Here is the Code Behind:</h3>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      lblDisplayDate.Text = DateTime.Now.ToString("T");
  }
  
  protected void btnPostback_Click(object sender, EventArgs e)
  {
      System.Text.StringBuilder sb = new System.Text.StringBuilder();
      sb.Append(@"&lt;script language='javascript'&gt;");
      sb.Append(@"var lbl = document.getElementById('lblDisplayDate');");
      sb.Append(@"lbl.style.color='red';");
      sb.Append(@"&lt;/script&gt;");
  
      if(!ClientScript.IsStartupScriptRegistered("JSScript"))
      {
          ClientScript.RegisterStartupScript(this.GetType(),"JSScript",
          sb.ToString());
      }
  }
  
  protected void btnPostBack2_Click(object sender, EventArgs e)
  {
      System.Text.StringBuilder sb = new System.Text.StringBuilder();
      sb.Append(@"&lt;script language='javascript'&gt;");
      sb.Append(@"var lbl = document.getElementById('lblDisplayDate');");
      sb.Append(@"lbl.style.color='red';");
      sb.Append(@"&lt;/script&gt;");
  
      if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock"))
      {
          ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock",  
          sb.ToString());
      } 
   }
  </code></pre>
  
  <p>The problem is when I click the <code>btnPostBack</code> button, it does a postback and changes the label to red, but when I click the <code>btnPostBack2</code>, it does a postback, but the label color does not change to red.  Why is this?  Is it because the label is not initialized?</p>
  
  <p>I also read that if you are using an <code>UpdatePanel</code>, you need to use <code>ScriptManager.RegisterStartupScript</code>, but if I have a <code>MasterPage</code>, would I use <code>ScriptManagerProxy</code>?</p>