禁用特定控件的视图状态
我即将部署我的网站,但在运行一些测试后,我可以看到每个页面上的视图状态太大,并且导致一个服务器进程占用大量内存。
我想禁用控件上的视图状态,我可以禁用它,EnableViewState="false"
,但在我在控件上添加此控件之前,我对可以禁用它的控件有点困惑在。
谁能告诉我控件可以禁用其视图状态的条件是什么?
一个例子:
<a id="A5" href="~/" runat="server">
<img src="~/images/logo.png" runat="server" />
</a>
我应该禁用这两个控件的视图状态吗?它们永远不会改变,本质上是静态资源。
I'm about to deploy my website, but after running some tests I can see that the viewstate is far too large on each page, and it's causing one server process to soak up huge amounts of memory.
I want to disable viewstate on the controls I can disable it on, EnableViewState="false"
, but before I go through adding this on controls, I'm a bit confused about which controls I can disable it on.
Could anyone tell me what conditions a control can have it's viewstate disabled are?
An example:
<a id="A5" href="~/" runat="server">
<img src="~/images/logo.png" runat="server" />
</a>
Should I disable viewstate on those two controls? They are never changed, are in essence static resources.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以安全地在图像和链接等控件上禁用它。
我将从顶级城镇开始,即页面级别。通常,当我完成网站上的工作后,我会首先在页面级别禁用所有仅内容页面上的 ViewState。
然后,我将查看工作表单/应用程序页面并在本地禁用链接/图像控件。任何不需要在回发过程中保留其状态的事物都是候选者。 GridView 是影响 ViewState 大小的常见问题,我自己通常倾向于使用 ListView。我特别避免在网格中嵌套任何类型的控件 - 从开始设计 UI 的那一刻起我就牢记这一点。
Yes you could safely disable it on controls such as images and links.
I would start from the top town, that is, at page-level. Generally when I have finished working on a site, I will disable ViewState on all content-only pages first at page level.
Then, I'll look at working forms/app pages and disable links/images controls locally. Anything that does not need to retain its state across a postback is a candidate. GridViews are the usual offenders WRT ViewState size and I generally tend to use ListViews myself. I particularly avoid any kind of control nesting in Grids - and I bear this in mind from the moment I start to design the UI.