ASP.NET 控件和更新面板

发布于 2024-07-14 14:47:04 字数 248 浏览 5 评论 0原文

我正在动态创建一系列嵌套在更新面板内的客户端组件控件。 我第一次创建控件时,一切都按预期工作,但是,当我在更新面板上触发更新并且它执行部分回发时,控件会返回几个 javascript 错误,描述控件如何在页面上注册。

我收到一系列错误,内容如下: “错误:Sys.InvalidOperationException:两个具有相同 id“master_ctl40_CCB_PALETTES”的组件无法添加到应用程序中”

有人有什么想法吗?

I am creating a series of client side component controls on the fly that are nested inside a update panel. The first time I create the controls, everything works as desired, however, when i trigger an update on the update panel and it does a partial postback the controls come back with several javascript errors describing how the control is already registered on the page.

I get a series of errors that say something about like:
"Error: Sys.InvalidOperationException: Two components with the same id "master_ctl40_CCB_PALETTES" can't be added to the application"

Any ideas anyone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

她如夕阳 2024-07-21 14:47:04

尝试这些技巧:

  1. 在 Page_Load 上放置 uxFailedControl.ID = DateTime.Now.ToString(); 它将确保您的控件在每次页面重新加载(完全或部分)时都具有唯一的 ID,因此理论上您不应该再看到“相同的 id”错误。
  2. 如果您在模态弹出窗口中显示控件:每次从服务器隐藏弹出窗口时,请从其容器(面板、页面、控件等)中删除控件。使用 uxModalPopupPanel.Controls.Clear(); 或 uxModalPopupPanel.Remove(uxFailedControl);
  3. 完成调试后,将 ScriptManager 的 ScriptMode 属性设置为“Release”。 它将防止内部 AJAX 异常冒泡到浏览器。

Try these tricks:

  1. On Page_Load put uxFailedControl.ID = DateTime.Now.ToString(); It will ensure your control has unique ID every time page reloads (fully or partially), so theoretically you shouldn't see anymore "same id" errors.
  2. If you display your control in Modal Popup: Every time you hide the popup from the server, remove the control from it's container (Panel, Page, Control, etc.) Use uxModalPopupPanel.Controls.Clear(); or uxModalPopupPanel.Remove(uxFailedControl);
  3. When you are done with debugging set ScriptMode property of your ScriptManager to "Release". It will prevent internal AJAX exceptions to be bubbled up to the browser.
小傻瓜 2024-07-21 14:47:04

在哪种情况下您会将组件添加到更新面板? 即,您是否将它们放置在页面加载事件中而不进行回发检查,或者将它们放置在更新面板加载事件中? ETC...

In which event are you adding the components to the update panel? I.e. have you placed them inside the page load event without a postback check or have you placed them inside the update panel load event? etc...

一百个冬季 2024-07-21 14:47:04

看起来您的客户端对象被创建了不止一次。

如果您希望客户端控件在更新面板刷新时被替换,它们应该继承自 Sys.UI.Control,该控件在其构造函数中采用一个元素。 当该元素被更新面板替换时,客户端对象将被处置然后重新创建。 如果您当前在服务器端使用 ScriptComponentDescriptor 来定义客户端控件实例,则您需要切换到 ScriptControlDescriptor。

听起来,您的客户端对象只是从 Sys.Component 继承,该对象将一直保留到手动处置为止,这就是为什么您会收到有关多个组件具有相同 ID 的错误。

我建议不要在每次回发时都使用新的 ID - 这只会不断创建新的客户端对象,而不会清理旧的对象。

Looks like your client object is being created more than once.

If you want your client side controls to be replaced when the update panel they're in refreshes, they should inherit from Sys.UI.Control, which takes takes an element in its constructor. When that element is replaced by the update panel, the client object will be disposed and then re-created. If you're currently using a ScriptComponentDescriptor on the server side to define the client control instance, you'll want to switch to a ScriptControlDescriptor.

By the sounds of it, your client objects just inherit from Sys.Component, which will hang around until they're manually disposed, which is why you're getting an error about having more than one component with the same ID.

I would advise against using a new ID every post back - this will just keep creating new client objects without ever cleaning up the old ones.

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