今天调试程序时发现一个很奇怪的问题,当在onload中遍历所有的控件时,会引起gridview的视图状态丢失,后来经过多次试验,发现代码:
protected List<Control> Components
{
get
{
List<Control> AList = new List<Control>();
AddControls(this,AList);
return AList;
}
}
/// <summary>
/// 增加一个控件和它的子控件到数组中
/// </summary>
/// <param name="AList"></param>
private void AddControls(Control AControl,List<Control> AList)
{
if( AControl.HasControls()) //<===这行代码不加就会丢失视图状态,太奇怪了
{
foreach(Control AChild in AControl.Controls)
{
AList.Add(AChild);
AddControls(AChild,AList);
}
}
}
转载于:https://www.cnblogs.com/lalacha/archive/2009/05/19/1460364.html
最后
以上就是重要金鱼最近收集整理的关于遍历Page中所有控件的一个奇怪问题的全部内容,更多相关遍历Page中所有控件内容请搜索靠谱客的其他文章。
发表评论 取消回复