获取母模版页的变量和属性值
母模版:
C#代码:
public partial class MasterPage : System.Web.UI.MasterPage
{
public int UserId {
get { return 342; }
}
public string UserName = "shenjk";
protected void Page_Load(object sender, EventArgs e)
{
}
}
在页面中获取该值:
C#代码:
protected void Page_Load(object sender, EventArgs e)
{
PropertyInfo pl = this.Master.GetType().GetProperty("UserId");
object o = pl.GetValue(this.Master, null); //o=342
FieldInfo f = this.Master.GetType().GetField("UserName");
object o1 = f.GetValue(this.Master); //o1=shenjk
}