UpdatePanel 代码隐藏错误“页面不能为空”
我正在尝试在代码隐藏中为我的控件创建一个更新面板。但我收到以下错误:
页面不能为空。请确保此操作是在 ASP.NET 请求的上下文中执行的。
我的代码:
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
}
任何 ideia?
谢谢, 费尔南多
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决。我的错=)。在我需要将 Contentplaceholder 控件放入页面之前。
Form.Controls.Add(控件);
然后我将“control.Controls.Add(up)”更改为“control.Controls.AddAt(i, up)”,用带有 updatepanel 的控件覆盖没有 updatepanel 的控件,一切正常。
谢谢,费尔南多
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