动态创建 ASP.NET 用户控件的多个实例:如何创建它,冲突会在哪里?

发布于 2024-09-13 12:16:53 字数 739 浏览 2 评论 0原文

我以前没有在 ASP.NET 中看到过这种实现,但我正在考虑一个外观和行为如下的 UI:

概念概述

  • TabControl 已加载,第一个选项卡包含一个网格
  • 当一行双击,将创建一个包含记录详细信息的新选项卡
  • 选项卡/记录详细信息的内容由用户控件创建
  • 可以创建许多选项卡,因此将创建用户控件的许多实例

我知道 ASP.NET 将重命名我的 (runat="server") ID 是给我的,我可以使用 jQuery 或 ASP.NET 服务器端代码来处理该 ID...我关心的是:

  • 我如何询问 ASP .NET 为我的用户控件的每个 N 个实例生成唯一 ID(将在占位符中呈现)
  • 我如何实际创建该控件的额外实例?
  • 我还需要记住什么?

由于我不想回发,所以我正在考虑将我的实现基于 ComponentArt 的 回调控件,并使用ASP.net用户控件来实现此效果。这将允许我做大多数需要回发的事情,但不会刷新页面上的所有元素......只是包含用户控件的部分。话虽如此,我并不局限于特定的实现。

I haven't seen this implemented before in ASP.NET, but am thinking about a UI that would look and act like this:

Conceptual Overview

  • A TabControl is loaded and the first tab contains a grid
  • When a row is double-clicked, a new tab is created with the record detail
  • The content of the tab/record detail is created by a usercontrol
  • Many tabs could be created, and therefore many instances of the usercontrol will be created

I know ASP.NET will rename my (runat="server") ID's for me, and that I can use jQuery or ASP.NET server-side code to work with the ID's... My concerns are:

  • How can I ask ASP.NET to generate a unique ID for each Nth instance of my usercontrol (to be rendered in a placeholder)
  • How do I actually create that extra instance of the control?
  • What else do I need to keep in mind?

Since I don't want postbacks I'm considering basing my implementation off of ComponentArt's Callback Control, and using ASP.net usercontrols to achieve this effect. This will allow me to do most things that require a postback, but won't refresh all the elements on a page... just the section that contains the user control. That being said, I'm not tied to a particular implementation.

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

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

发布评论

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

评论(1

柏林苍穹下 2024-09-20 12:16:53

您应该查看 Page.LoadControl 方法。它工作得很好,据我记得你在页面上放置了占位符并将控件加载到占位符中,这就是你控制 id 的方式。

使用此方法效果不佳的一件事是当您的控件引发 Page 对象必须处理的事件时。如果您的控件是独立的,那么您应该不会有问题。

这可能会帮助您开始:
http://www.codeproject.com/KB/aspnet/LoadingUSerControl.aspx

You should look into the Page.LoadControl method. It works nicely and as far as I remember you put placeholders on your page and load the controls into the PlaceHolders, that's how you control the ids.

One thing that doesn't work out so well with this approach is when your control raises events that your Page object has to handle. If your control is selfcontained however you shouldn't have a problem.

This might help you get started:
http://www.codeproject.com/KB/aspnet/LoadingUSerControl.aspx

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