web自定义控件*ascx应用示例

WebUserControl.ascx.cs 文件

public delegate void myDelegate(string a,string b);

        public event myDelegate EventRefresh;

        private string _客户id;
        private string _录音编号;

        public string p_客户id
        {
            set { _客户id = value; }
            get { return _客户id; }
        }

        public string p_录音编号
        {
            set { _录音编号 = value; }
            get { return _录音编号; }
        }

        //属性在刷新页面时清空
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                this.TextBox1.Text = this.p_客户id;
                this.TextBox2.Text = this.p_录音编号;
            }
        }

        //获取属性
        public void Buttion1_Click(object sender, EventArgs e)
        {
            this.TextBox1.Text = this.p_客户id;
            this.TextBox2.Text = this.p_录音编号;
        }

        //公有方法
        public string m_Add(string i, string j)
        {
            this.TextBox3.Text = i;
            this.TextBox4.Text = j;
            Int32 k = Convert.ToInt32(i) + Convert.ToInt32(j);
            this.TextBox5.Text = k.ToString();
            return k.ToString();
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            EventRefresh(this.TextBox6.Text,this.TextBox7.Text);//触发事件,刷新列表
        }

调用页:

 public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            this.WebUserControl1.EventRefresh += new WebUserControl.myDelegate(m_刷新);//委托--m_刷新列表-方法来执行--事件
      
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            this.WebUserControl1.p_客户id = this.TextBox1.Text;
            this.WebUserControl1.p_录音编号 = this.TextBox2.Text;

            this.WebUserControl1.Buttion1_Click(sender, e);//让Web控件取属性
        }


        protected void Button2_Click(object sender, EventArgs e)
        {
            this.TextBox5.Text = this.WebUserControl1.m_Add(this.TextBox3.Text, this.TextBox4.Text);
        }

        private void m_刷新(string c,string d)
        {
            this.TextBox6.Text = "两个参数已传入:  " +c +" , " + d  ;
        }
    }

原文地址:https://www.cnblogs.com/hailexuexi/p/1780201.html