Only one instance of a ScriptManager can be added to the page. - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

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

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

    I'm having a problem: I have a user control which includes a ScriptManager. This causes issues in the back end, as it already includes a ScriptManager, and there can only be one. So when editing the page where the control is located, I see the message "Only one instance of a ScriptManager can be added to the page." in the control box. It works fine on the front end, though.

    I looked around on how I'm supposed to handle this problem, and I ended up finding stuff. I saw I'm supposed to remove the ScriptManager from my control, and decorate my control class with the [RequireScriptManager(true)] attribute instead. I did, but it doesn't work. My control contains RadGrids that rely on a RadAjaxManager and a RadAjaxLoadingPanel. When I remove my ScriptManager and add the attribute instead, then the AJAX magic no longer works, and I get full postbacks instead.

    What am I doing wrong?
  • Hi,

    It'll be useful to have a solution to this, I used too RadGrid and RadAjaxManager to increase performance on client side. But contributor don't really understand errors in backend.

    regards,
    Nicolas
  • Hi ,

    One option would be to load ScriptManager conditionally, by checking whether you are in Design mode.

    You can easily achieve this  using our ControlExtensions:

    IsDesignMode - static method which determines whether the control is in Sitefinity design mode - you  are editing a page. There are also  IsPreviewMode- determines whether the control is in Sitefinity preview mode.
    IsBackend -determines whether a control instance is in backend.  Please refer to the sample code below:

    protected override void OnPreRender(EventArgs e)
             base.OnPreRender(e);       
             if(this.IsDesignMode() && !this.IsPreviewMode())
             
                //do something
       
             
              
       

    alternatively, you can use SystemManager.IsDesignMode when checking for DesignMode in a control.

    You can also check this blog post, in which we explain the reasons for the behavior you are experiencing and how to proceed in such scenario.

    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Boyan,

    I did try to add or remove the ScriptManager dynamically before posting this topic, but couldn't get anything to work. Same message whatever I do: "Only one instance of a ScriptManager can be added to the page."

    I just tried this, for example:

    protected override void OnPreRender(EventArgs e)
        base.OnPreRender(e);
        if (this.IsDesignMode() && !this.IsPreviewMode())
        
            this.Controls.Remove(this.scriptManager);
            this.scriptManager.Dispose();
        

    Also tried OnInit, and so on...
    What should I do, exactly? Maybe set a ScriptManager attribute or something, rather than trying to remove it?

    By the way, I don't think the UpdatePanel article applies to my situation. I don't use UpdatePanels.

    Also, could you comment on the RequireScriptManager attribute? I don't get it. Is it useless?

    PS: I saw this, but it seems like a lot of troubles just for this... Surely there is a more simple solution?
    Not to mention ScriptManager doesn't have a "Visible" property here, while that guy suggests using it...

    Thanks for your help.
  • Hello Thomas,

    The RequireScriptManager attribute will automatically check the Include RadScriptManager property of the page, where the user control marked with that attribute is used. Please note that the supported scenario for using a control with Ajax functionality is to declare the ScriptManager and AjaxManager on a masterpage, which you will later use as a template for the page where the control will be located. This will ensure that the required managers are being loaded before everything else on the page. You can then use RadAjaxManagerProxy to ajaxify your user control. For your convenience, please find attached a sample user control using a RadGrid, where the desired functionality is implemented.

    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Boyan,

    Please could you provide an up to date link for GridSample.rar.  Also, I already have a masterpage used as a template for Sitefinity.  Do I need to create a new masterpage, used by my user control, or use the existing one?