When writing your own controls, we can't always just define properties for built-in types such as String,int--night roads are always going to hit ghosts. How do we save view state when complex attributes (custom types) are encountered? This problem has been bothering me for a long time ...
I would like to use a few small examples to express their "ghost" experience.
Husband
Namespace Controls
{
using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Web.UI;
public class Husband:control
{public
Wife mywife
{
get
{
.
}
set
{
viewstate["mywife"] = value;
}} public
class Wife
{
private string m_name;
private int m_age;
public string Name
{get
{m_name;}
set {m_name= value;}
Public
int age
{get
{m_age;}
set {m_age= value;}
}
}
See this code, a lot of friends are expected to scold me, why, run under: found that will throw the following exception
Type ' Controls.wife ' in Assembly ' Controls, version=1.0.0.0, culture=neutral, Publickeytoken=null ' are not marked as serial Izable.
After seeing this anomaly, I used to add [Serializable]attribute to the front of the wife, plus it did run successfully but unfortunately, it was a way to get a brick.