I am trying to remove the Scriptmanager from a SharePoint page in code so I can swap it with the Ajax toolkit. However, when I use the following code I get:
Only one instance of a ScriptManager can be added to the page
The code errors on the Add statement. This has to be done via code as access to modify the master page source is not an option.
The code from my webpart that needs to replace the scriptmanager:
protected void GroupCalenderSourceControl_Init(object sender, EventArgs e)
{
//throw new NotImplementedException();
ScriptManager sm = ScriptManager.GetCurrent(Page);
if (sm == null)
{
Page.Controls.Add(new AjaxControlToolkit.ToolkitScriptManager());
}
else
{
if (!(sm is AjaxControlToolkit.ToolkitScriptManager))
{
Page.Controls.Remove(Page.FindControl(sm.ID));
Page.Master.Controls.Remove(Page.FindControl(sm.ID));
sm = null;
Page.Controls.Add(new AjaxControlToolkit.ToolkitScriptManager());
}
}
}