ASP.Net、拖放、回发和控件 ID

发布于 2024-07-15 10:54:11 字数 783 浏览 3 评论 0原文

标题试图总结问题,但这里有更详细的总结:我们的网页是用户控件的集合,它们在视觉上呈现为矩形报告小部件,这些小部件在 AJAX 更新面板中设置。 我们让用户能够将小部件拖放到页面上预设的“区域”。

拖放功能运行良好。 我们使用 AJAX 调用 Web 服务来使用用户的新持久性设置更新数据库。

当我们从这些小部件之一进行回发时,就会发生“但是”。 回发被发送到服务器,它呈现一个更新,该更新被发送回客户端(全部通过 AJAX,因为 updatepanel)。 然后,我们在客户端上收到“无法找到带有 ID 的 UpdatePanel...”消息,因为文档层次结构已更改,但客户端上的控件 ID 尚未更新。

我们尝试了 Rick Strahl 的解决方案链接文本< /a>,它允许我们在客户端上创建静态控件 ID。 不过,这会破坏回发功能...我假设未设置 isPostBack 属性,因为服务器无法将控件 ID 与已知的层次结构元素相匹配。

我们正在考虑在拖放控件后使用 Javascript 在客户端重置控件 ID。 显然,这需要复制 .Net 的命名算法——我们认为这并不明智。 也许我们可以使用单独的更新面板并要求服务器在删除后向我们发送新的控件 ID?

显然,我们的想法已经用完了。

我意识到这可能太长了,我会很乐意编辑、提供代码示例等来帮助您帮助我们。 先感谢您。

The title attempts to summarize the problem, but here's a more detailed summary: our web page is a collection of usercontrols, which visually render as rectangular reporting widgets, which are set in AJAX updatepanels. We are giving the user the ability to drag and drop the widgets to pre-set "zones" on the page.

The drag and drop functionality works fine. We use AJAX calls to a web service to update a database with the user's new settings for persistence.

The "however" happens when we do a postback from one of these widgets. The postback is sent to the server, it renders an update, which is sent back to the client (all via AJAX, because of the updatepanel). We then get a "Could not find UpdatePanel with ID..." message on the client, because the document hierarchy has changed, but the control IDs have not been updated on the client.

We tried Rick Strahl's solution to this link text, which allowed us to create static control IDs on the client. This breaks the postback functionality, though... the isPostBack property is not set, I'm assuming because the server can't match the control ID with a known hierarchy element.

We're thinking about possibly resetting the control ID on the client side after it's dragged and dropped, using Javascript. Obviously, this would require duplicating .Net's naming algorithm--not smart, we're thinking. Maybe we can use a separate updatepanel and ask the server to send us the new control ID after it's dropped?

Obviously, we're running out of ideas.

I realize this is probably too long, and I'll happily edit, provide code samples, etc. to help you help us. Thank you in advance.

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

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

发布评论

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

评论(2

薄凉少年不暖心 2024-07-22 10:54:11

只是出于兴趣,您是否检查过发回的 UpdatePanel 的 id,该 id 是否是预期的? 您可以挂钩 ASP.NET 的客户端页面生命周期 AJAX 像这样检查启动回发的控件的 id

<script type="text/javascript">

  function pageLoad(sender, args)
  {
      var prm = Sys.WebForms.PageRequestManager.getInstance();

      prm.add_initializeRequest(InitializeRequest);
      prm.add_endRequest(EndRequest);

      //fires when an async postback is initialized
      function InitializeRequest(sender, args) 
      {
        alert(args._postBackElement.id)
      }

      //fires when an async postback is complete
      function EndRequest(sender, args) 
      {
        alert(sender._postBackSettings.sourceElement.id)
      }
  }

</script>

Just out of interest, have you inspected the id of the UpdatePanel that posts back, and is the id one that is expected? You can hook into the client page lifecycle of ASP.NET AJAX like so to inspect the id of the control initiating the postback

<script type="text/javascript">

  function pageLoad(sender, args)
  {
      var prm = Sys.WebForms.PageRequestManager.getInstance();

      prm.add_initializeRequest(InitializeRequest);
      prm.add_endRequest(EndRequest);

      //fires when an async postback is initialized
      function InitializeRequest(sender, args) 
      {
        alert(args._postBackElement.id)
      }

      //fires when an async postback is complete
      function EndRequest(sender, args) 
      {
        alert(sender._postBackSettings.sourceElement.id)
      }
  }

</script>
抚笙 2024-07-22 10:54:11

您可以使用 ASp.Net 的内置系统(称为 WebParts)来实现可拖动的页面元素。

该系统支持回发,并且可以使用 Visual Studio 轻松实现

搜索 Webparts 教程,例如:

http://www.ondotnet.com/pub/a/dotnet/2005/01/10/liberty.html

希望这有帮助

You could use ASp.Net's built in system for draggable page elements called WebParts.

The system works with postbacks and can be easily implemented with Visual Studio

Have a search for webparts tutorials such as:

http://www.ondotnet.com/pub/a/dotnet/2005/01/10/liberty.html

Hope this helps

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