比如我在defaut.aspx 页里面写了个 方法 private void aaa(){}  在default 页里面托了个web控件  我想在这个web控件 里调用 default页的 aaa()方法 怎么实现呢

解决方案 »

  1.   

    你这种思想很不好
    你的web 用户控件并一定就在defaut.aspx上用,如果在WebForm.aspx上使用这个控件,那没有aaa方法呢
      

  2.   

    可以反过来做.
    在你的用户控件里写一个事件,然后default页中在你定义的这个事件中写相应代码或者调用你现有的方法.
      

  3.   

    知道了,俺下次不跑题了,看下面
    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(); 
        }
      

  4.   

    .ascx
    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");
    }
      

  5.   

    楼上的比我的简单好多,而且还能输出fuck, 不错,分给你了楼上的