反射代码
用反射方法使用户控件动态调用父页面的方法
用户控件:
private void Button1_Click(object sender, System.EventArgs e)
{
//用反射方法动态调用父页面的方法
System.Web.UI.Page p = this.Page;
Type pageType = p.GetType();
MethodInfo mi = pageType.GetMethod("SetLabel");
mi.Invoke(p,new object[]{"你这个大猪猪!"});
}
父页面:
public void SetLabel(string str)
{
this.Label1.Text = str;;
}
this.Page.GetType().GetMethod("WriteOptLog").Invoke(this.Page,new object[]{"添加新图书(条形码:" + sb.ToString()+")"});
用户控件:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
父页面:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
this.Page.GetType().GetMethod("WriteOptLog").Invoke(this.Page,new object[]{"添加新图书(条形码:" + sb.ToString()+")"});