I have a unique problem. I'm working on a .net solution where I do not have access to the main aspx pages. Mainly, I cannot modify any of them. I'm building a whole bunch of usercontrols, that will get used on various .aspx page. I want to use the updatepanel, and one knows it requires the scriptmanager control to be on the page.
So - what I do have access to is a placeholder on the .aspx page. What I want to try and do is place the scriptmanager control in this placeholder. I already know how to do this, by getting a reference to the context page and then adding a control in there. However, I'm having an issue with the timing. I have the updatepanel on the .ascx control, and I have the scriptmanager load in the Page_PreLoad event of the control. This doesn't seem to work, as it complains that "'The control with ID 'updUsers' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.' Its obvious the updatepanel is loading before the Page_Preload event.
Question is, exactly what method can I use to load the control? Can this be done at all? Is there a better way to do this?
EDIT:
I've tried almost all the events:
protected void Page_PreInit(object sender, EventArgs e)
protected override void OnInit(EventArgs e)
DETAILS
Just to clarify, this is what the usercontrol code looks like:
public partial class PollModule : ModuleBase
{
protected override void OnInit(EventArgs e)
{
Page page = HttpContext.Current.Handler as Page;
page.Init += delegate(object sender, EventArgs e_Init)
{
if (ScriptManager.GetCurrent(page) == null)
{
ScriptManager sMgr = new ScriptManager();
page.Form.Controls.AddAt(0, sMgr);
}
};
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
SOMEWHAT WORKING EDIT
I was able to get it partially working by attaching to the updatepanel init, so I know however way I am adding the scriptmanager is working, so I guess I am just missing the right page event to attach to.