跟踪回发时要重建的动态控件计数的 Microsoft 官方方法是什么?

发布于 2024-10-09 00:34:15 字数 307 浏览 3 评论 0原文

当基于任意且不断变化的大小的数据源创建动态控件时,在回发操作之后(即在ASP.NET 页面事件生命周期期间的服务器端)特别是应该重建动态控件的点?用于检索和重建的数量存储在哪里?

我所说的“官方”是指微软的做法。存在诸如会话存储等黑客行为,但我想知道真正的或至少是微软推荐的方式。我一直无法找到说明此信息的文档页面。通常,代码示例使用一组已知数字的动态控件。好像如果不这样做会更困难。

更新:我不是询问用户控件或声明性控件的静态表达式,而是询问完全从代码隐藏动态注入控件,无论它们是我的、第三方的还是内置的 ASP。 NET 控件。

When creating dynamic controls based on a data source of arbitrary and changing size, what is the official way to track exactly how many controls need to be rebuilt into the page's control collection after a Postback operation (i.e. on the server side during the ASP.NET page event lifecycle) specifically the point at which dynamic controls are supposed to be rebuilt? Where is the arity stored for retrieval and reconstruction usage?

By "official" I mean the Microsoft way of doing it. There exist hacks like Session storage, etc but I want to know the bonafide or at least Microsoft-recommended way. I've been unable to find a documentation page stating this information. Usually code samples work with a set of dynamic controls of known numbers. It's as if doing otherwise would be tougher.

Update: I'm not inquiring about user controls or static expression of declarative controls, but instead about dynamically injecting controls completely from code-behind, whether they be mine, 3rd-party or built-in ASP.NET controls.

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

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

发布评论

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

评论(1

寒江雪… 2024-10-16 00:34:16

这在很大程度上取决于当前的问题以及您正在重新创建的控件的类型。它们都是简单的文本框还是各种不同的复杂自定义用户控件。这里的主要内容是:如果您希望动态控件在回发后重新获得状态,则必须在页面生命周期的 Init 阶段重新创建它。

无论如何。基本上没有什么比微软方式微软推荐的方式更好的了。当您动态添加多个相同类型的简单控件时,带有计数的隐藏字段就可以解决问题,但是当您有多个复杂的控件时,则必须使用其他方法。您仍然可以隐藏字段并在其中保存控件的完整类型字符串(即 System.Web.UI.WebControls.TextBox)并重新实例化它们。但考虑一个更复杂的示例,将各种控件放在页面的不同部分......并将它们初始化为特定状态。那会更具挑战性。因此没有微软的方法...推荐的方法是在初始化阶段重新创建。就是这样。

一切都可以解决,但有时人们在 UI 中采取了错误的方向,使用不同的方法可以更轻松地完成事情。

附加说明

一般而言,Asp.net 使用的 ViewState 这种全状态技术被认为是 Web 开发人员最糟糕的罪魁祸首。这就是为什么 Asp.net MVC 开发人员认为新框架是极好的,因为它更适合无状态 HTTP 协议。我就是其中之一。 :D

This greatly depends on the problem at hand, and the type of controls you're recreating. Are they all simple text boxes or various different complex custom user controls. the main thing here is: if you want your dynamic control to regain state after a post-back, you have to re-create it in the Init phase of a page life-cycle.

Anyway. There's nothing like a Microsoft way or Microsoft recommended way basically. When you're dynamically adding several simple controls of the same type a hidden field with a count would do the trick, but when you have several complex controls other ways would have to be used. You could still hidden fields and save control's full type strings in them (ie. System.Web.UI.WebControls.TextBox) and re-instantiate them. But think of an even more complex example of putting various controls on different parts in the page... And initializing them to a specific state. That would be a bit more challenging. Hence no Microsoft way... The recommended way is to recreate in Init phase. And that's it.

Everything can be solved, but sometimes one took a wrong direction in the UI and things could be done easier using a different approach.

Additional explanation

This state-full technique of ViewState that Asp.net uses is considered the worse culprit with web developers in general. That's why Asp.net MVC developers think the new framework is bliss since its much more suited to the state-less HTTP protocol. Me being one of them. :D

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