动态添加多个部分 - ASP.NET

发布于 2024-12-10 15:42:38 字数 251 浏览 0 评论 0原文

我有一个网页,其中有未确定数量的部分(由文本框、下拉列表等的集合组成)。用户单击“添加部分”按钮,该部分应该动态添加。用户可以添加的部分数量没有上限。然后有一个“保存”按钮,此时我需要遍历所有部分并保存数据。

我的第一个想法是将该部分创建为用户控件,每当用户单击服务器端的“添加部分”时,我都会动态添加该部分。

我想避免动态添加用户控件,因为我觉得这有点奇怪。我想了解是否可以利用 jquery 或客户端模板来实现这里的用例。

想法或建议?

I have a web page which has a non determined number of sections (made up of a collection of textbox, dropdowns etc). A user clicks on "Add Section" button and this section should be added dynamically. There is no upper limit on how many sections a user can add. There is then a Save button at which time the I need to traverse through all the sections and persist the data.

My first thought is to create the section as a user control that I dynamically add whenever a user clicks on the "Add section" on the server side.

I'd like to avoid doing adding user controls dynamically as I feel it's a little quirky. I am trying to understand if I can leverage jquery or client templates for the use case here.

Thoughts or suggestions?

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

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

发布评论

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

评论(1

罪歌 2024-12-17 15:42:39

我不认为使用用户控制解决方案有任何错误。类似的(服务器端)技术是使用数据绑定控件,例如 Repeater 或 ListView - 项目模板将定义该部分。服务器端解决方案的优点是它可以快速构建,并且可以使用 ASP.NET 基础设施,例如视图状态(这样您就不必担心在回发时维护状态)。典型的 ASP.NET Forms 开发人员很容易理解其中的逻辑。另一方面是更大的标记大小,在添加部分时进行多个大数据传输(无论您使用完整还是部分回发都没有多大关系 - 视图状态将是正在传输的数据的重要部分)。

我个人更喜欢客户端模板方法,因为您可以避免回发和相关的数据传输。但有两个问题 - a)相对复杂的显示/更新部分的逻辑 - 记住你的代码在两个地方碎片化 - js 和服务器端代码 - 典型的开发人员会发现很难理解 b)对 java 脚本的依赖(有时,如果不支持js,则必须提供后备机制)

I don't think there is any wrong in using user control solution. A similar (server side) technique would be to use a data-bound control such as Repeater or ListView - the item template would define the section. The advantage with server side solution is that it can be quickly built and can use ASP.NET infrastructure such as view-state (so that you don't have to worry about maintaining state on post-backs). Typical ASP.NET Forms developer would easily understand the logic. Flip side is that larger markup size, multiple large data transfers while adding sections (whether you use full or partial post-back will not matter much - view-state will be significant part of data being transfer).

I will personally prefer client templating approach because you avoid post-backs and associated data transfers. But there are two issues - a) relatively complex logic for displaying/updating sections - remember your code is fragmented at two places - js and server side code - typical developers would find it difficult to understand b) reliance of java-script (sometime, you must provide for a fallback mechanism if js is not supported)

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