zoukankan
html css js c++ java
实现 IStateManager 接口的服务器控件在设定属性时的注意点
设定属性后,要添加一句
ViewState.SetItemDirty() 的调用,这样在后续的阶段,StateBag.SaveViewState() 方法被调用时,才会保存该属性的值。
例子如下:
public
virtual
ImageAlign RightImageAlign
{
get
{
object
o
=
ViewState[
"
ItemRightImageAlign
"
];
if
(o
==
null
)
return
ImageAlign.NotSet;
else
return
(ImageAlign) o;
}
set
{
ViewState[
"
ItemRightImageAlign
"
]
=
value;
ViewState.SetItemDirty(
"
ItemRightImageAlign
"
,
true
);
}
}
通过 Reflector 看到 System.Web.UI.StateBag 类的
SaveViewState() 方法的代码如下,可以验证这一点:
internal
object
SaveViewState()
{
ArrayList list1
=
null
;
ArrayList list2
=
null
;
if
(
this
.bag.Count
!=
0
)
{
IDictionaryEnumerator enumerator1
=
this
.bag.GetEnumerator();
while
(enumerator1.MoveNext())
{
StateItem item1
=
(StateItem) enumerator1.Value;
if
(item1.IsDirty)
{
if
(list1
==
null
)
{
list1
=
new
ArrayList(
5
);
list2
=
new
ArrayList(
5
);
}
list1.Add(enumerator1.Key);
list2.Add(item1.Value);
}
}
if
(list1
!=
null
)
{
return
new
Pair(list1, list2);
}
}
return
null
;
}
查看全文
相关阅读:
@codeforces
@codeforces
@hdu
@hdu
@bzoj
@bzoj
@topcoder
推荐系统主题相关资料
Python统计百分比及排序
如何发布及部署asp.net网站
原文地址:https://www.cnblogs.com/RChen/p/204525.html
最新文章
【托业】【跨栏】3
【托业】【跨栏】REVIEW2
【托业】【跨栏阅读】错题集-REVIEW1
【托业】【新东方托业全真模拟】TEST09~10-----P5~6
【托业】【新东方托业全真模拟】TEST07~08-----P5~6
【托业】【新东方托业全真模拟】TEST05~06-----P5~6
【托业】新托业全真题库---TEST1
ES6系列_16之模块化操作
ES6系列_15之class类的使用
ES6系列_14之promise对象的简单使用
热门文章
ES6系列_13之Proxy进行预处理(简单学习)
ES6系列_12之map数据结构
@codeforces
@gym
@loj
@bzoj
@hdu
@bzoj
@bzoj
@codeforces
Copyright © 2011-2022 走看看