I'm attempting to add a ScriptManager control programmatically, but only if one doesn't exist on the page. I've found many examples for this that put the logic inside Page_Init, which makes sense (have since realized it doesn't make sense- see bottom edit), but I'm getting an exception before my Init method is ever hit.
protected void Page_Init(object sender, EventArgs e)
{
if (ScriptManager.GetCurrent(Page) == null)
{
ScriptManager sMgr = new ScriptManager();
Page.Form.Controls.AddAt(0, sMgr);
}
}
This makes me think Sitecore is getting in the way somehow. Has anyone successfully done this using Sitecore?
Thanks.
EDIT: The exception I'm receiving is as follows: "The control with ID 'filtersUpdatePanel' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it."
EDIT^2: What was really going on here was that Page_Init is too late in the life cycle to attach a ScriptManager (in my case). With Init, all child events are fired first, then Page. The UpdatePanel's init didn't see a ScriptManager, so it threw an exception. Putting the ScriptManager logic in the UpdatePanel init solved the issue.