View state is definitely a headache for asp.net developers, especially those who are interested in control development. All along, I have been very confused, searching the internet for a long time, these two days only a little bit of perspective. And since I have been diving, I decided to take the first bubble today.
When we derive new controls from control or WebControl, we can use the Modifier property without defining the ViewState attribute, so it should be derived. When we look at the source code with reflector, we know that it's in control.
Protected virtual StateBag ViewState
{
get
{
.
}
set
{
}
}
Here comes a new type of statebag, what is it? Let's start with the source code:
StateBag from System.Web.UI, its statement is as follows:
Public sealed class Statebag:istatemanager, IDictionary, ICollection, IEnumerable .....
Here we focus on istatemanager, because we need to derive from this interface when we customize view state management for our custom controls. But this time I'm not going to talk about it.
By name, we can generally think of it as a container, a container of ' state '.
Let's look at the implementation of StateBag:
Private IDictionary bag;
private bool marked;
Public StateBag (bool ignoreCase)
{
this.marked = false;
This.ignorecase = ignoreCase;
This.bag = this. Createbag ();
private IDictionary createbag ()
{return
new HybridDictionary (this.ignorecase);
}