是否可以在ASP .NET中禁用ViewState?
-
28-10-2019 - |
题
我在我的网站上使用了第三方服务器端控件(ASP.NET的Teleeled RadControls)。菜单控件具有复杂的结构,这使视图状态的大小膨胀,从而影响加载时间。我不知道viewstate的详细信息,只是Web服务器使用它来跟踪控件值。
由于我网站上的大多数页面仅显示,是否可以禁用未接受用户输入的视图状态?无论如何,所有动态项目都会在页面加载时重新生成。
解决方案
如果您使用的是asp.net 4,则可以使用ViewStateMode
属性来控制控件的视图状态生成。 ViewStateMode
如果您不使用asp.net 4,则可以在页面或控件级别打开视图状态。 通用标签
http://msdn.microsoft.com / en-us / library / system.web.ui.page.enableviewstate.aspx
其他提示
In the top of your aspx page add the parameter enableViewstate="false" on the pages that doesn't need it. it won't disable the viewstate completely though, but reduce the size seriously
I haven't tested this, but I think it's possible..
In your Web.config file add the attribute to the pages tag instead, and then on those pages you need it enabled, add the attribute with true in the top
System.Web.UI.WebControls.CheckBox checkBox = new System.Web.UI.WebControls.CheckBox();
checkBox.EnableViewState = false;
There are different ways of disabling ViewState. In your case, I would recommend disabling the viewstate on the control:
<telerik:RadMenu ViewStateMode="Disabled"