//动态在CS代码中给页面增加用户控件 UserControl userControl1 = (UserControl)this.LoadControl("../UserCtrls/WordList.ascx"); //给动态添加的用户控件的属性赋值(利用反射技术)首先引用using System.Reflection;命名空间 //获取用户控件的Type Type userCtrlType = userControl1.GetType(); //设定用户控件要赋值的属性 PropertyInfo propertyInfo = userCtrlType.GetProperty("showHeader"); //赋值 propertyInfo.SetValue(userControl1, false, null); //向页面添加控件 Page.Controls.Add(userControl1);
|