何时启用/禁用视图状态

发布于 2024-07-05 09:43:46 字数 110 浏览 9 评论 0原文

我通常会禁用 ASP.net 控件的视图状态,除非我明确知道我需要它们的视图状态。 我发现这可以显着减小生成的 HTML 的页面大小。

这是好的做法吗? 什么时候应该启用或禁用?

I generaly disable viewstate for my ASP.net controls unless I explicitly know I am going to require view state for them. I have found that this can significantly reduce the page size of the HTML generated.

Is this good practice? When should be enabled or disabled?

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

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

发布评论

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

评论(6

痴情 2024-07-12 09:43:46

我认为这是很好的做法。 许多 ASP.NET 开发人员没有意识到他们的视图状态给发送到用户浏览器的 HTML 添加了巨大的负担。

I think it's good practice. Many ASP.NET devs are unaware that their viewstates add tremendous baggage to the HTML that's being sent to their users' browsers.

自找没趣 2024-07-12 09:43:46

是的,这是一个非常好的主意。 有人可能会说,微软应该默认禁用它,就像缓存一样。

要了解 Viewstate 在大小增加方面有多糟糕,您可以使用名为 Viewstate Analyzer。 当您开发的现有应用程序启用了 Viewstate 时,这特别有用。

禁用 Viewstate 的另一个好理由是,当您有大量组件依赖于它时,在后期阶段很难禁用它。

Yes it is a very good idea. One could argue that it should have been disabled by default by Microsoft, just like caching.

To see how bad Viewstate is in terms of size increased you can use a tool called Viewstate Analyzer. This is particularly useful when you have an existing application developed with Viewstate enabled.

Another good reason to disable Viewstate is that it is really hard to disable at a later stage, when you have loads of components depending on it.

彩扇题诗 2024-07-12 09:43:46

这绝对是个好主意,没有什么比开发人员每次在 Page_Load 中绑定 dataGrid 但还要提交视图状态的页面更糟糕的了!

如果您计划使用 AJAX 扩展中的 UpdatePanel,这也是一个非常好的主意,这意味着您在 UpdatePanel 请求期间提交的内容会减少。

(不要因为说 UpdatePanel 很好而生气:P)

Definately a good idea, nothing worse that a page which a developer is binding a dataGrid in the Page_Load every time but also submitting the viewstate!

It's also a really good idea if you are planning on using the UpdatePanel from the AJAX Extensions, it means you're submitting less during the UpdatePanel request.

(Don't flame for saying that an UpdatePanel can be good :P)

我是男神闪亮亮 2024-07-12 09:43:46

您可以在“ASP.NET 状态管理建议”文章 对您做出决定很有帮助。

通常,在 ASP.NET 2.0 及更高版本中,由于引入了用于存储引发事件等所需信息的控件状态,禁用 ViewState 的破坏性较小。

You may find the information contained in the "ASP.NET State Management Recommendations" article on MSDN useful for making your decision.

Generally in ASP.NET 2.0 and above disabling the ViewState is less destructive due to the introduction of the Control State for storing informaton required for raising events etc.

谁许谁一生繁华 2024-07-12 09:43:46

这是一个很好的做法。 除非您在回发时使用 ViewState 值,或者某些复杂控件本身需要它们,否则最好将 ViewState 保存为发送到客户端的内容的一部分。

It's a good practice. Unless you use ViewState values on postbacks, or they are required by some complex control itself it's good idea to save on ViewState as part of what will be sent to the client.

离鸿 2024-07-12 09:43:46

_Viewstate 可能会不必要地增加需要传输的字节数。
因此,除非下次要使用该数据,否则最好将其关闭。

_Viewstate can unnecessarily increase the number of bytes that need to be transferred.
So unless the data is going to be used the next time , it's a good idea to switch it off.

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