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
SystemManager.IsDesignMode
when checking for DesignMode in a control.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();
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.
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?