开发者

AJAX Timer Control to load a control every 5 secs

I have the following Hierarchy

Page -> Usercontrol1 with ( asp:UpdatePanel & asp:Timer) ---> Usercontrol2 with (asp:UpdatePanel) with a grid

In page load i am loading usercontrol1, then usercontrol1 loads usercontrol2.

I am getting following error :-

"Cannot unregister UpdatePanel with ID 'UpdatePanel1' since it was not registered with the开发者_运维百科 ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added"

Now I have tried with

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 });

        }

    }

After this i am getting the following error :-

"The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."

If i remove the update panel from usercontrol2 this works fine... but need an ajax post back in usercontrol2.

Can someone help ?

Thanks Saif

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜