开发者

UpdatePanel codebehind error "Page cannot be null"

i'm trying create a upd开发者_如何学编程atepanel 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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜