How to save custom objects in view status

xiaoxiao2021-03-06  94

Background: B / S three-layer structural system, instantiate the object of the business layer in the performance layer, and use this object to perform business rules, access the data layer.

Question: In the performance, an business object is performed, and when it operates this object, it is found that it cannot be added to ViewState, prompting error:

Type "AMMETERCHG" must be marked as Serializable or TypeConvert other than REFERENCECONVERTER can be placed in the view state.

Solution: Implement the class to implement the iSerialization interface, allow it to be serialized

The code for implementing the interface part is as follows:

#region ISerializable members protected ammeterChg (SerializationInfo info, StreamingContext context) {this.customer_id = info.GetString ( "customer_id"); this.am_id_old = info.GetString ( "am_id_old"); this.abc = info.GetString ( "abc "); this.ycbds_old = info.GetDouble (" ycbds_old ");} public void GetObjectData (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) {

Info.addValue ("Customer_ID", Customer_ID); Info.addValue ("AM_ID_OLD", AM_ID_OLD); Info.addValue ("ABC", ABC); Info.addValue ("YCBDS_OLD", YCBDS_OLD);} # endregion === ============================================================================================================================================================================================================= ====== Customer_ID, am_id_old, yCBDS_OLD is the private variable of the properties of this class!

转载请注明原文地址:https://www.9cbs.com/read-123558.html

New Post(0)