What causes the 'Cannot unregister UpdatePanel' error?

前端 未结 8 1246
长情又很酷
长情又很酷 2020-12-17 17:22

I\'ve got a UserControl that contains an UpdatePanel. When I put that on a page, it throws the following error:

Cannot unregister UpdatePanel with ID

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 18:01

    I hope this helps someone else as it drove me nuts. After finding various tidbits of info here and there on here and elsewhere, I finally came up with the following fix. Note, I am not dynamically creating this update panel here or anywhere else and most info out there was related to creating this control dynamically, which I was not.

    I was using an update panel inside a web user control used on a page inherited by a master page with the script manager. I don't know if this combo was what was causing it, but this is how I fixed it (inside the web user control where the update panel is utilized):

    protected override void OnInit(EventArgs e)
    {
        ScriptManager sm = ScriptManager.GetCurrent(this.Page);
        MethodInfo m = (
        from methods in typeof(ScriptManager).GetMethods(
            BindingFlags.NonPublic | BindingFlags.Instance
            )
        where methods.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")
        select methods).First();
    
        m.Invoke(sm, new object[] { updatePanel });
        base.OnInit(e);
    }
    

提交回复
热议问题