web 用户控件如何调用宿主页的方法 比如我在defaut.aspx 页里面写了个 方法 private void aaa(){} 在default 页里面托了个web控件 我想在这个web控件 里调用 default页的 aaa()方法 怎么实现呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你这种思想很不好你的web 用户控件并一定就在defaut.aspx上用,如果在WebForm.aspx上使用这个控件,那没有aaa方法呢 可以反过来做.在你的用户控件里写一个事件,然后default页中在你定义的这个事件中写相应代码或者调用你现有的方法. 知道了,俺下次不跑题了,看下面defaut页面: protected void Page_Load(object sender, EventArgs e) { WebUserControl1.SayHellEvent += delegate { SayHello(); }; } private void SayHello() { Response.Write("Hello World"); }WebUserControl: public delegate void SayHello(); public event SayHello SayHellEvent; protected void Button1_Click(object sender, EventArgs e) { SayHellEvent(); } .ascxpublic event EventHandler myEvent;protected void Button1_Click(object sender, EventArgs e){ if (myEvent != null) myEvent(this, EventArgs.Empty);}.aspxprotected void Page_Load(object sender, EventArgs e){ WebUserControl11.myEvent += new EventHandler(aaa);}protected void aaa(object sender, EventArgs e){ Response.Write("fuck");} 楼上的比我的简单好多,而且还能输出fuck, 不错,分给你了楼上的 sql语句求解 一条excel数据导入三个关联的表,如果出错的话该怎么取消插入操作 大哥们救命啊,小女子遇到麻烦了 能否在读取SQLServer2000数据的同时转换数据类型? 求救! MVC Razor 怎么使用事务 为什么首次打开页面JS都没有效果,必须要重新刷新一下页面才行?? NVelocity集合下标 哪有比较全面的关于代码书写规范的文章 如何在vs.net环境下以拖动控件的方式连接并显示Access数据表 初学ajax,望指教下 怎么修改单元格的class?
你的web 用户控件并一定就在defaut.aspx上用,如果在WebForm.aspx上使用这个控件,那没有aaa方法呢
在你的用户控件里写一个事件,然后default页中在你定义的这个事件中写相应代码或者调用你现有的方法.
defaut页面:
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl1.SayHellEvent += delegate { SayHello(); };
} private void SayHello()
{
Response.Write("Hello World");
}WebUserControl:
public delegate void SayHello();
public event SayHello SayHellEvent;
protected void Button1_Click(object sender, EventArgs e)
{
SayHellEvent();
}
public event EventHandler myEvent;protected void Button1_Click(object sender, EventArgs e)
{
if (myEvent != null)
myEvent(this, EventArgs.Empty);
}
.aspx
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl11.myEvent += new EventHandler(aaa);
}protected void aaa(object sender, EventArgs e)
{
Response.Write("fuck");
}