title: How to check if client script is already registered during a partial postback
body: <p>Below is the code I've currently implemented.</p>
  
  <pre><code>if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey))
  {
    ScriptManager scriptManager = ScriptManager.GetCurrent(page);
    if (scriptManager != null &amp;&amp; scriptManager.IsInAsyncPostBack)
    {
      //if a MS AJAX request, use the Scriptmanager class
      ScriptManager.RegisterStartupScript(Page, Page.GetType(), scriptKey, script, true);
    }
    else
    {
      //if a standard postback, use the standard ClientScript method
      Page.ClientScript.RegisterStartupScript(Page.GetType(), scriptKey, script, true);
    }
  }
  </code></pre>
  
  <p>I'm doing as suggested in <a href="https://stackoverflow.com/questions/1952817/asp-net-javascript-inside-ajax-updatepanel/1953122#1953122">this</a> answer so that I can register startup script on both times i.e. when there is partial postback and a full postback.</p>
  
  <p>The problem is <code>Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey)</code> always (even when the script is registered before) returns false when it is partial postback. And I couldn't find ScriptManager.IsStartupScriptRegistered (static) method. As a result of this, additional script is emitted on all partial/async postbacks.</p>
  
  <p>Please note that I'm using script manager of AjaxControlToolkit version 4.1 i.e. <code>ToolkitScriptManager</code> in my masterpage. But I don't thing it has something to do with this.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>  &lt;asp:UpdatePanel ID="ContactDetailsUpdatePanel" UpdateMode="Conditional" runat="server"&gt;
      &lt;Triggers&gt;
        &lt;asp:AsyncPostBackTrigger ControlID="UpdateContactDetailsButton" EventName="Click" /&gt;
      &lt;/Triggers&gt;
      &lt;ContentTemplate&gt;
        &lt;div id="ContactDetailsContent" class="contact_details_content"&gt;
          &lt;div class="customer_contactdetails_left_pane"&gt;
            &lt;div class="customer_name_field"&gt;
              &lt;asp:Label ID="CustomerNameLabel" runat="server" Text="Customer" /&gt;
              &lt;asp:TextBox ID="CustomerNameValue" runat="server" /&gt;
            &lt;/div&gt;
            &lt;div class="customer_address_field"&gt;
              &lt;asp:Label ID="CustomerAddressLabel" runat="server" Text="Address" /&gt;
              &lt;asp:TextBox ID="CustomerAddressValue" runat="server" /&gt;
              &lt;asp:TextBox ID="CustomerAddressValue1" runat="server" /&gt;
              &lt;asp:TextBox ID="CustomerAddressValue2" runat="server" /&gt;
              &lt;asp:TextBox ID="CustomerAddressValue3" runat="server" /&gt;
            &lt;/div&gt;
            &lt;div class="customer_postcode_field"&gt;
              &lt;asp:Label ID="CustomerPostcodeLabel" runat="server" Text="Postcode" /&gt;
              &lt;asp:TextBox ID="CustomerPostcodeValue" runat="server" /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="customer_contactdetails_right_pane"&gt;
            &lt;div&gt;
              &lt;asp:Label ID="CustomerContactLabel" runat="server" Text="Contact" /&gt;
              &lt;asp:TextBox ID="CustomerContactValue" runat="server" /&gt;
            &lt;/div&gt;
            &lt;div&gt;
              &lt;asp:Label ID="CustomerTelephoneLabel" runat="server" Text="Telephone" /&gt;
              &lt;asp:TextBox ID="CustomerTelephoneValue" runat="server" /&gt;
            &lt;/div&gt;
            &lt;div&gt;
              &lt;asp:Label ID="CustomerMobileLabel" runat="server" Text="Mobile" /&gt;
              &lt;asp:TextBox ID="CustomerMobileValue" runat="server" /&gt;
            &lt;/div&gt;
            &lt;div&gt;
              &lt;asp:Label ID="CustomerFaxLabel" runat="server" Text="Fax" /&gt;
              &lt;asp:TextBox ID="CustomerFaxValue" runat="server" /&gt;
            &lt;/div&gt;
            &lt;div&gt;
              &lt;asp:Label ID="CustomerEmailLabel" runat="server" Text="Email" /&gt;
              &lt;asp:TextBox ID="CustomerEmailValue" runat="server" /&gt;
            &lt;/div&gt;
            &lt;div&gt;
              &lt;asp:Label ID="CustomerWebLabel" runat="server" Text="Web" /&gt;
              &lt;asp:TextBox ID="CustomerWebValue" runat="server" /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="update_button_field"&gt;
          &lt;asp:Button ID="UpdateContactDetailsButton" runat="server" Text="Update" 
            onclick="UpdateContactDetailsButton_Click" /&gt;
        &lt;/div&gt;          
      &lt;/ContentTemplate&gt;    
    &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p><strong>NOTE:</strong> To be able to understand the progress on this problem, please see the comments on <a href="https://stackoverflow.com/questions/2826695/where-is-scriptmanager-isstartupscriptregistered-method/2837262#2837262">this</a> answer before replying.</p>
  
  <p><strong>UPDATE</strong><br/>
  I have implemented a temporary solution to this problem by putting a check in javascript that if the script is already executing then do not execute twice. Javascript is still being spitted multiple times on every partial postback. Couldn't prevent it.</p>
  
  <p>As the views to this post are increasing, I can see that there are other people who might also want answer to this problem.</p>