views:

150

answers:

1

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

A: 

Resolved. My bad =). Before I needed put Contentplaceholder control in the page.

Form.Controls.Add(control);

Then I changed "control.Controls.Add(up)" for "control.Controls.AddAt(i, up)", overwriting the control without updatepanel by a control with updatepanel, and everything worked well.

Thanks, Fernando

Nandoviski