UpdatePanel codebehind error "Page cannot be null"

Posted by Nandoviski on Stack Overflow See other posts from Stack Overflow or by Nandoviski
Published on 2010-04-16T14:20:14Z Indexed on 2010/04/16 14:23 UTC
Read the original article Hit count: 316

Filed under:
|
|

Hi guys, i'm trying create a updatepanel for my controls in a codebehind. But i get the follow error:

Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.

My code:

List<Control> novoControl = new List<Control>();
control.Controls.ForEach<Control>(c => novoControl.Add(c));

control.Controls.Clear(); // This control is a contentplaceholder of my masterpage

control.Controls.Add(IcpScriptManager); //Add ScriptManager in the page

foreach (Control item in novoControl)
{
   UpdatePanel up = new UpdatePanel();
   up.ID = "up_" + item.ID;
   up.ChildrenAsTriggers = true;

   up.UpdateMode = UpdatePanelUpdateMode.Conditional;

   up.ContentTemplateContainer.Controls.Add(item);

   control.Controls.Add(up); //ERROR happens here
}

Any ideia??

Thanks, Fernando

© Stack Overflow or respective owner

Related posts about updatepanel

Related posts about ASP.NET