UpdatePanel 代码隐藏错误“页面不能为空”

发布于 2024-08-29 11:42:38 字数 766 浏览 0 评论 0原文

我正在尝试在代码隐藏中为我的控件创建一个更新面板。但我收到以下错误:

页面不能为空。请确保此操作是在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有你我更好 2024-09-05 11:42:38

已解决。我的错=)。在我需要将 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文