禁用子控件的视图状态加载

发布于 2024-08-09 17:35:47 字数 284 浏览 5 评论 0原文

我在 ASP.NET 页面中动态创建了很多 Web 控件。在某些回发场景中(当我单击 LinkBut​​ton 时),我想跳过旧 Web 控件树的加载并立即生成新树。不幸的是,当我生成新树时,旧树的视图状态被加载到其中。

我希望能够针对这个特定场景禁用视图状态加载过程,但是在加载新树后,视图状态应该正常工作。

我已经通过重写 Web 控件的 LoadViewState 方法解决了部分问题,但不幸的是,这会禁用特定于该控件的视图状态,而不是其子控件(文本框、按钮等)。

是否可以?

谢谢。

I have a lot of web controls created dynamically in an ASP.NET page. In certain postback scenarios (when I click a LinkButton), I want to skip the loading of the old tree of web controls and immediately generate the new tree. Unfortunately, when I generate the new tree, the viewstate of the old tree is loaded into it.

I want to be able to disable the viewstate loading process for this specific scenario, but after the new tree is loaded, the viewstate should work normally.

I've already solved part of the problem, by overriding the LoadViewState method of the web controls, but, unfortunately, this disables the viewstate specific for the control, not for his children too (textboxes, buttons etc.).

Is it possible?

Thank you.

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

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

发布评论

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

评论(3

り繁华旳梦境 2024-08-16 17:35:47

您可以尝试在加载视图状态后创建新树,例如在 Page_Load 中。

You can try creating the new tree after the viewstate has been loaded, e.g. in Page_Load.

压抑⊿情绪 2024-08-16 17:35:47

您可以通过在将新数据绑定到树之前清除树的内容来以编程方式执行此操作。它应该是这样的

tree.nodes.clear()

,然后你就好像树是空的一样,通过限制它或通过以编程方式添加节点来添加数据,

tree.Nodes.Add(New TreeNode("name of node"))

现在对于我收集的常规控件,你将遇到一个如果您不使用视图状态,则会出现一大堆问题。您可以使用 controlname.controls.clear 以类似的方式从控件树中删除它们。现在您的问题主要是附加这些控件还是您不想承担视图状态的负担?我建议,如果是后者,您可以以编程方式清除控件并将视图状态服务器端存储在某处,以便可以从内存加载它而不是使用您的带宽。

至于控件的动态加载,您需要确保您的新控件带有不同的 ID。我在我的一个应用程序中所做的实际上是保留旧控件,使它们不可见并清除视图状态,然后在下一次调用时我实际上将它们从树中删除。

You can do this programatically by clearing the contents of the tree before binding the new data to it. It should be somehting along the lines of

tree.nodes.clear()

and then you just go on as if the tree is empty and add you data by either bounding it or by adding the nodes programatically with

tree.Nodes.Add(New TreeNode("name of node"))

now for regular controls which I gather you are using you will run into a whole host of problems if you don't use viewstate. You can remove them from the control tree in a similar fashion using controlname.controls.clear. Now is you problem primarily the appending of these contorls or is it that you don't want to carry the burden of viewstate? I suggest that if it's the latter that you clear your controls programatically and store viewstate server side somewhere so that it can be loaded from memory instead of using your bandwidth.

As for dynamical loading of controls you will need to ensure tha tyour new controls carry different ID's for them. What I've done in one of my apps is actually keep the old controls, make them invisible and clear the viewstate then on the next call I actually remove them from the tree.

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