Where is ScriptManager.IsStartupScriptRegistered method?

Posted by Ismail S on Stack Overflow See other posts from Stack Overflow or by Ismail S
Published on 2010-05-13T12:26:25Z Indexed on 2010/05/19 6:10 UTC
Read the original article Hit count: 696

Below is my code

if (!Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey))
{
  ScriptManager scriptManager = ScriptManager.GetCurrent(page);
  if (scriptManager != null && 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);
  }
}

I'm doing as suggested in this answer so that I can register startup script on both times i.e. when there is partial postback and a full postback.

The problem is Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), scriptKey) always returns false when it is partial postback. And I couldn't find ScriptManager.IsStartupScriptRegistered method. As a result of this additional script is emitted on all partial/async postbacks.

Please note that I'm using script manager of AjaxControlToolkit version 4.1 i.e. ToolkitScriptManager in my masterpage. But I don't thing it has something to do with this.

UPDATE

  <asp:UpdatePanel ID="ContactDetailsUpdatePanel" UpdateMode="Conditional" runat="server">
    <Triggers>
      <asp:AsyncPostBackTrigger ControlID="UpdateContactDetailsButton" EventName="Click" />
    </Triggers>
    <ContentTemplate>
      <div id="ContactDetailsContent" class="contact_details_content">
        <div class="customer_contactdetails_left_pane">
          <div class="customer_name_field">
            <asp:Label ID="CustomerNameLabel" runat="server" Text="Customer" />
            <asp:TextBox ID="CustomerNameValue" runat="server" />
          </div>
          <div class="customer_address_field">
            <asp:Label ID="CustomerAddressLabel" runat="server" Text="Address" />
            <asp:TextBox ID="CustomerAddressValue" runat="server" />
            <asp:TextBox ID="CustomerAddressValue1" runat="server" />
            <asp:TextBox ID="CustomerAddressValue2" runat="server" />
            <asp:TextBox ID="CustomerAddressValue3" runat="server" />
          </div>
          <div class="customer_postcode_field">
            <asp:Label ID="CustomerPostcodeLabel" runat="server" Text="Postcode" />
            <asp:TextBox ID="CustomerPostcodeValue" runat="server" />
          </div>
        </div>
        <div class="customer_contactdetails_right_pane">
          <div>
            <asp:Label ID="CustomerContactLabel" runat="server" Text="Contact" />
            <asp:TextBox ID="CustomerContactValue" runat="server" />
          </div>
          <div>
            <asp:Label ID="CustomerTelephoneLabel" runat="server" Text="Telephone" />
            <asp:TextBox ID="CustomerTelephoneValue" runat="server" />
          </div>
          <div>
            <asp:Label ID="CustomerMobileLabel" runat="server" Text="Mobile" />
            <asp:TextBox ID="CustomerMobileValue" runat="server" />
          </div>
          <div>
            <asp:Label ID="CustomerFaxLabel" runat="server" Text="Fax" />
            <asp:TextBox ID="CustomerFaxValue" runat="server" />
          </div>
          <div>
            <asp:Label ID="CustomerEmailLabel" runat="server" Text="Email" />
            <asp:TextBox ID="CustomerEmailValue" runat="server" />
          </div>
          <div>
            <asp:Label ID="CustomerWebLabel" runat="server" Text="Web" />
            <asp:TextBox ID="CustomerWebValue" runat="server" />
          </div>
        </div>
      </div>
      <div class="update_button_field">
        <asp:Button ID="UpdateContactDetailsButton" runat="server" Text="Update" 
          onclick="UpdateContactDetailsButton_Click" />
      </div>          
    </ContentTemplate>    
  </asp:UpdatePanel>

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-ajax