Error: Only one instance of a ScriptManager can be added to the page.

3 posts, 0 answers
  1. Pierre
    Pierre avatar
    1 posts
    Member since:
    Jun 2008

    Posted 17 Jul 2009 Link to this post

    Hello friends,

    I am developing a Usercontrol that will be mounted on the main page of a WSS 3.0 Site Collection using "Return of SmartPart v3.0". Done all the AJAX configurations on the server and tested it using the Sample Ajax User control included in the with the SmartPart installation.

    I have also moved the Telerik:RadScriptManager & the Telerik:RadAjaxmanager to the WSS Master page:

    Seen below:

    default.master

    <WebPartPages:SPWebPartManager id="m" runat="Server" /> 
          <!-- Added --> 
       <telerik:RadScriptManager ID="radScriptManager" runat="server"
        </telerik:RadScriptManager> 
        <telerik:RadAjaxManager ID="radAjaxManager" runat="server"
            <AjaxSettings> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
      <!-- End of Added --> 

    Using RadAjaxManajerProxy from the user control. Here is the user control ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MessageControl.ascx.cs" Inherits="Cubana.Web.UserControl.UserControls.MessageControl" %> 
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik"  %> 
     
        <telerik:RadCodeBlock ID="radCodeBlock" runat="server"
            <script type="text/javascript"
                var messageId, currentMessage, currentRowIndex = null
     
                function pageLoad(sender, args)  
                { 
     
                } 
              
                function rowSelected(sender, args)  
                { 
                    $find("<%= radTabStrip.ClientID %>").set_selectedIndex(0); 
                    var ajaxManager = $find('<%= radAjaxManagerProxy.ClientID %>'); 
                    var selectedIndex = args.get_itemIndexHierarchical(); 
                    ajaxManager.ajaxRequestWithTarget('<%= this.UniqueID %>', selectedIndex) 
                    DisableControls(); 
     
                } 
                 
                 
                function tabSelected(sender, args)  
                { 
                     
                    switch (args.get_tab().get_index()) { 
                        case 1: 
                            { 
                                EnableControls(); 
                                break; 
                            } 
                        default: 
                            { 
                                DisableControls();  
                                break; 
                            } 
                } 
     
     
                function EnableControls()  
                { 
                    var txtUsernameState = $find("<%= txtUsername.ClientID %>"); 
                    txtUsernameState.enable(); 
     
                    var txtSubjectState = $find("<%= txtSubject.ClientID %>"); 
                    txtSubjectState.enable(); 
     
                    var txtReceivedState = $find("<%= txtReceived.ClientID %>"); 
                    txtReceivedState.disable(); 
     
                    var txtBodyState = $find("<%= txtBody.ClientID %>"); 
                    txtBodyState.enable(); 
                } 
     
                function DisableControls()  
                { 
                    var txtUsernameState = $find("<%= txtUsername.ClientID %>"); 
                    txtUsernameState.disable(); 
     
                    var txtSubjectState = $find("<%= txtSubject.ClientID %>"); 
                    txtSubjectState.disable(); 
     
                    var txtReceivedState = $find("<%= txtReceived.ClientID %>"); 
                    txtReceivedState.disable(); 
     
                    var txtBodyState = $find("<%= txtBody.ClientID %>"); 
                    txtBodyState.disable(); 
                } 
                     
                } 
                 
                 
            </script> 
     
        </telerik:RadCodeBlock> 
        <style type="text/css"
            .body 
            { 
                margin: 0px; 
                padding: 0px; 
                height: 100%; 
                width: 100%; 
                background-color: #FFFFE0; 
            } 
            .grid td 
            { 
                cursor: pointer; 
            } 
            .button 
            { 
                background-color: Silver; 
                border: medium none; 
                height: 28px; 
                width: 90px; 
            } 
            .label 
            { 
                font-family:Verdana; 
                font-size:10px; 
            } 
        </style> 
    <form id="form1" runat="server">  
    <!--<telerik:RadScriptManager ID="radScriptManager" runat="server"
        </telerik:RadScriptManager>--> 
    <div style="height: 100%; padding: 10px"
        <%--<telerik:RadAjaxManager ID="radAjaxManager" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="rgData"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="rgData" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager>--%> 
        <telerik:RadAjaxManagerProxy ID="radAjaxManagerProxy" runat="server"
           </telerik:RadAjaxManagerProxy> 
        <telerik:RadWindowManager ID="radWindowManager" runat="server"
                </telerik:RadWindowManager>  
                 <telerik:RadTabStrip ID="radTabMailBox" Style="margin-top: 10px;" 
            SelectedIndex="0" AutoPostBack="True" runat="server"  
            ontabclick="radTabMailBox_TabClick"
            <Tabs> 
                <telerik:RadTab Text="Inbox" Selected="True" /> 
                <telerik:RadTab Text="Sent Items" Selected="False" /> 
            </Tabs> 
        </telerik:RadTabStrip> 
        <telerik:RadGrid ID="radgridList" CssClass="grid" runat="server" GridLines="None" 
            AutoGenerateColumns="False" OnSelectedIndexChanged="radgridList_SelectedIndexChanged"
            <MasterTableView TableLayout="Fixed"
                <Columns> 
                    <telerik:GridBoundColumn UniqueName="MessageId" DataField="MessageId" DataType="System.Guid" 
                        Visible="false" HeaderText="MessageId"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="UserName" DataField="UserName" Visible="true" 
                        HeaderText="Sender"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="Title" DataField="Title" Visible="true" HeaderText="Subject"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="DateTimeCreated" DataField="DateTimeCreated" 
                        Visible="true" HeaderText="Received"
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
            <ClientSettings> 
                <Selecting AllowRowSelect="true" /> 
                <ClientEvents OnRowSelected="rowSelected" /> 
                <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
            </ClientSettings> 
        </telerik:RadGrid> 
        <telerik:RadTabStrip ID="radTabStrip" OnClientTabSelected="tabSelected" Style="margin-top: 10px;" 
            SelectedIndex="0" AutoPostBack="True" OnTabClick="RadTabStrip_TabClick" runat="server"
            <Tabs> 
                <telerik:RadTab Text="View Message" Selected="True" /> 
                <telerik:RadTab Text="New Message" Selected="False" /> 
            </Tabs> 
        </telerik:RadTabStrip> 
        <div style="border: 1px solid threedshadow;"
            <table border="0" style="margin-top: 20px; width: 100%;"
                <tr> 
                    <td> 
                    </td> 
                    <td> 
                        <asp:Button ID="btnDelete" CssClass="button" Style="float: right; margin-right: 10px; 
                            color: black; font-weight: bold;" Text="Delete" runat="server" OnClick="btnDelete_Click" /> 
                        <asp:Button ID="btnSend" CssClass="button" Style="float: right; margin-right: 10px; 
                            color: black; font-weight: bold;" Text="Send" runat="server" OnClick="btnSend_Click" /> 
                    </td> 
                </tr> 
                <tr> 
                    <td> 
                        <asp:Label ID="lblUserName" Text="Sender" CssClass="label" runat="server"></asp:Label> 
                    </td> 
                    <td> 
                        <telerik:RadComboBox ID="txtUsername" CssClass="label" runat="server" Width="500px" 
                            AllowCustomText="True" /> 
                        &nbsp; &nbsp;<asp:Label ID="lblUsernameError" Text="Please choose a Recipient" CssClass="label" 
                            runat="server" ForeColor="Red" Visible="False"></asp:Label> 
                    </td> 
                </tr> 
                <tr> 
                    <td> 
                        <asp:Label ID="lblSubject" Text="Subject" CssClass="label" runat="server"></asp:Label> 
                    </td> 
                    <td> 
                        <telerik:RadTextBox ID="txtSubject" runat="server" Width="500px" /> 
                    </td> 
                </tr> 
                <tr> 
                    <td> 
                        <asp:Label ID="lblReceived" Text="Received" CssClass="label" runat="server"></asp:Label> 
                    </td> 
                    <td> 
                        <telerik:RadTextBox ID="txtReceived" runat="server" Width="250px" /> 
                    </td> 
                </tr> 
                <tr> 
                    <td style="vertical-align: top;"
                        <asp:Label ID="lblBody" Text="Body" CssClass="label" runat="server"></asp:Label> 
                    </td> 
                    <td> 
                        <telerik:RadTextBox ID="txtBody" runat="server" Height="500px" Width="500px" Columns="2" 
                            TextMode="MultiLine" /> 
                    </td> 
                </tr> 
            </table> 
        </div> 
    </div> 
    </form> 
     

    Even though there is only one ScriptManager present I am getting the following error when the main page loads from the Site Collection.

    Only one instance of a ScriptManager can be added to the page.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: Only one instance of a ScriptManager can be added to the page.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [InvalidOperationException: Only one instance of a ScriptManager can be added to the page.]
    System.Web.UI.ScriptManager.OnInit(EventArgs e) +384553
    Telerik.Web.UI.RadScriptManager.OnInit(EventArgs e) +68
    System.Web.UI.Control.InitRecursive(Control namingContainer) +333
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210
    System.Web.UI.Control.AddedControl(Control control, Int32 index) +198
    System.Web.UI.ControlCollection.Add(Control child) +80
    SmartPart.SmartPart.CreateChildControls() +46
    System.Web.UI.Control.EnsureChildControls() +87
    System.Web.UI.Control.PreRenderRecursiveInternal() +44
    System.Web.UI.WebControls.WebParts.WebPart.PreRenderRecursiveInternal() +42
    System.Web.UI.Control.PreRenderRecursiveInternal() +171
    System.Web.UI.Control.PreRenderRecursiveInternal() +171
    System.Web.UI.Control.PreRenderRecursiveInternal() +171
    System.Web.UI.Control.PreRenderRecursiveInternal() +171
    System.Web.UI.Control.PreRenderRecursiveInternal() +171
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842




    Any help would be greatly appreciated. Let me know if I have to sent through more information.

    Thank you,
    Pierre.
  2. Toby Carter
    Toby Carter avatar
    3 posts
    Member since:
    Oct 2009

    Posted 17 Mar 2010 Link to this post

    I'm sort of surprised no one replied to this. If anyone else comes across this, the fix is simple... if you look in the HTML, he is using HTML comments to 'hide' the scriptmanager in the control. He needs to use the .NET comments (CTRL-K + CTRL-C). Otherwise, .NET will still likely see the control and react accordingly.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eliza Sahoo
    Eliza Sahoo avatar
    29 posts
    Member since:
    Jan 2010

    Posted 22 Apr 2010 Link to this post

    The following code snippet demonstrates how you can add an event handler as well as a CSS class to an element using ScriptManager
    Sys.UI.DomEvent  class provides API for attaching handlers to DOM element.
    Sys.UI.DomElement class provides API and Properties for manupulating DOM elements.
Back to Top