如:有用户控件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();
}

相关文章:

  • 2021-09-26
  • 2021-06-25
  • 2021-07-21
  • 2021-07-25
  • 2021-05-15
猜你喜欢
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-12-11
  • 2021-04-10
相关资源
相似解决方案