DataList控件添加到视图状态 [英] adding datalist into viewstate

查看:115
本文介绍了DataList控件添加到视图状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个的DataList 进入视图状态为:

 的ViewState [DataList控件] = dtlstForm;

和检索它作为:

 的DataList LIS =(DataList控件)的ViewState [DataList控件];

然后如下因素错误出现:


  

在大会'的System.Web类型System.Web.UI.WebControls.DataList',
  版本= 2.0.0.0,文化=中性公钥= b03f5f7f11d50a3a'是
  未标记为可序列化。



解决方案

的DataList 类是不可序列化(的SerializableAttibute已经无法在其上设置并且不实施的 ISerializable的接口)

这意味着NET框架不能序列化,放入ViewState中。

由于这是一个内置的类,你不能修改它是序列化。

作为一个DataList预计将持有相当多的信息,把它在ViewState中会导致ViewState的是巨大的,这将影响性能,因此它是有道理的不让它序列化。

也许你可以重新考虑你需要把ViewState中,只放少量进去(IDS例如列表)中的信息。

I have added one datalist into view state as:

ViewState["datalist"] = dtlstForm;

and retrieved it as:

DataList lis = (DataList)ViewState["datalist"];

then folowing error comes:

Type 'System.Web.UI.WebControls.DataList' in Assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.

解决方案

The DataList class is not serializable (the SerializableAttibute has not be set on it and it is not implementing the ISerializable interface).

This mean the .NET framework cannot serialize it and put it into ViewState.

Since this is a built in class, you cannot modify it to be serializable.

As a DataList is expected to hold quite a lot of information, putting it in ViewState would cause ViewState to be huge, which would impact performance, so it makes sense to not make it serializable.

Perhaps you can rethink the information you need to put in ViewState and only put a small amount into it (a list of IDs for example).

这篇关于DataList控件添加到视图状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆