概述
今天调试程序时发现一个很奇怪的问题,当在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中所有控件的一个奇怪问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复