在普通页面上动态加载用户控件,想把用户控件的方法委托给普通页面处理
请问如何实现
跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求
请问如何实现
跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求跪求
public partial class YourControl: System.Web.UI.UserControl
{}
//===================================
调用:
YourControl lc = (YourControl)this.LoadControl("你的控件.ascx");
lc.属性=***;PanelId.Controls.Add(lc);
public void jiazaiUserControl(string ucPath,string ucTitle)
{
this.PlaceHolder1.Controls.Clear();
Control uc = this.LoadControl(ucPath);
uc.ID = ucTitle;
this.PlaceHolder1.Controls.Add(uc);
Type ucType = uc.GetType();// this.PlaceHolder1.FindControl("NeiRong").GetType();
System.Reflection.MethodInfo mInfo = ucType.GetMethod("neirong"); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('"+mInfo.Name+"');</script>", false); neirongevent += new neirongdelegateHandler(ucType.GetMethod("neirong"));
}
最后这句出错
public void jiazaiUserControl(string ucPath,string ucTitle)
{
this.PlaceHolder1.Controls.Clear();
Control uc = this.LoadControl(ucPath);
uc.ID = ucTitle;
this.PlaceHolder1.Controls.Add(uc);
Type ucType = uc.GetType();// this.PlaceHolder1.FindControl("NeiRong").GetType();
System.Reflection.MethodInfo mInfo = ucType.GetMethod("neirong"); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('"+mInfo.Name+"');</script>", false); neirongevent += new neirongdelegateHandler(ucType.GetMethod("neirong"));
}
------------------------------------------------------------------------
删除以下代码
Type ucType = uc.GetType();// this.PlaceHolder1.FindControl("NeiRong").GetType();
System.Reflection.MethodInfo mInfo = ucType.GetMethod("neirong"); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('"+mInfo.Name+"');</script>", false); neirongevent += new neirongdelegateHandler(ucType.GetMethod("neirong"));
--------------------------------------------------------------------
在需要调用用户控件方法的地方加上下面代码if(this.PlaceHolder1.FindControl(ucTitle)!=null)
{
Control uc = this.PlaceHolder1.FindControl(ucTitle);
Type ucType = uc.GetType();
System.Reflection.MethodInfo mInfo = ucType.GetMethod("neirong");
mInfo.Invoke(uc, null);
}
其实mInfo.Invoke(uc, null);就是利用委托实现的
他高兴了我没多少分了,留着下次用,不好意思了各位