Friday, May 4, 2012

Cannot unregister UpdatePanel with ID 'bla bla' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported. Parameter name

Solution

protected override void OnInit(EventArgs e) {

base.OnInit(e);

this.UpdatePanel1.Unload += new EventHandler(UpdatePanel_Unload);

}



void UpdatePanel_Unload(object sender, EventArgs e) {

this.RegisterUpdatePanel(sender as UpdatePanel);

}



public void RegisterUpdatePanel(UpdatePanel panel) {

foreach (MethodInfo methodInfo in typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)) {

if (methodInfo.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")) {

methodInfo.Invoke(ScriptManager.GetCurrent(Page), new object[ { panel });

}

}


}