UserControl中调用Page中的函数 EventHandler [原]

Default.aspx:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace UserControlCallPageMethod
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Bind_Event();
        }
      
        private void SelectedStatusChanged(object sender, EventArgs e)
        {
            DropDownList drp = (DropDownList)sender;
            if (drp.SelectedIndex >= 0)
            {
                this.TextBox1.Text = drp.SelectedValue;
            }
        }

        public void Bind_Event()
        {
            this.WebUserControl1_1.OnStatusChanged += SelectedStatusChanged;
        }
    }
}
//===========================================================================================
WebUserControl1.ascx:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace UserControlCallPageMethod
{
    public partial class WebUserControl1 : System.Web.UI.UserControl
    {
        public EventHandler OnStatusChanged;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (OnStatusChanged != null)
            {
                OnStatusChanged(sender, e);
            }
        }
    }
}

posted @ 2007-09-23 14:33  RobotTech  阅读(384)  评论(0编辑  收藏  举报