如:有用户控件header、affiche,
在affiche中获取header的值(前提这些值必须public)
在affiche.cs中加入
多个属性值:
Page p = this.Parent.Page; UserControl uc = p.FindControl("header1") as UserControl;
Type pageType = uc.GetType();
FieldInfo[] myFields = pageType.GetFields(BindingFlags.Public | BindingFlags.Instance);
for (int i = 0; i < myFields.Length; i++)
{
Response.Write(string.Format("The value of {0} is: {1}", myFields[i].Name, myFields[i].GetValue(uc)));
}
单个属性值:
Page p = this.Parent.Page;
UserControl uc = p.FindControl("header1") as UserControl;
Type pageType = uc.GetType();
FieldInfo field = pageType.GetField("cityId", BindingFlags.Public | BindingFlags.Instance);
if (field != null)
{
CityId = field.GetValue(uc).ToString();
}
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2011/05/03/2035013.html,如需转载请自行联系原作者
本文介绍如何在一个用户控件中获取另一个用户控件的公共属性值,通过使用反射来实现跨控件的数据访问。
5994

被折叠的 条评论
为什么被折叠?



