The CMS I use struggles with UpdatePanels in some of my custom controls and master pages during edits. I'd like to convert them dynamically to regular panels on Page_Load or Page_Init or something based on whether the page is being edited.
I'd like to convert all the UpdatePanels on a page to Panels dynamically. Finding the UpdatePanels isn't an issue, all my pages inherit from a common base class, and all my controls inherit from a common base class -- so I can override the Page_Init or whatever.
I suspect I can't covert the UpdatePanel to a regular Panel. I thought about maybe finding the UpdatePanel, adding a Panel to the UpdatePanel's parent, then looping through each of the UpdatePanel's controls and adding them to the new Panel, then removing the UpdatePanel.
But if I add a new Panel, it'll be at the end, can you add a Panel in the middle... maybe with Insert? This shouldn't be difficult, but am I making it too difficult? Is there a simpler way? Anybody ever done stuff like this?
Thanks, Eric
Update I ended up override the OnInit function on my MasterPage base class to readd the UpdatePanel to the ScriptManager after it moved per Philippe's comment on http://msmvps.com/blogs/luisabreu/archive/2006/11/16/adding-removing-updatepanels-dynamicaly-from-a-page.aspx
protected override void OnInit(EventArgs e)
{
if (Page is CMSPage && Page.IsDesignMode())
{
foreach (UpdatePanel up in this.FindControls<UpdatePanel>())
{
up.Load += UpdatePanel_Load;
}
}
base.OnInit(e);
}
private void UpdatePanel_Load(object sender, EventArgs e)
{
UpdatePanel panel = sender as UpdatePanel;
MethodInfo m = (from methods in typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
where methods.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")
select methods).First();
if (panel == null || m == null)
return;
m.Invoke(ScriptManager.GetCurrent(Page), new object[] { panel });
}