为动态创建的控件添加事件绑定

来源:互联网 发布:linux more 查找内容 编辑:程序博客网 时间:2024/06/05 09:40
    protected override void Page_Load(object sender, EventArgs e)    {        if (IsPostBack)        {            Create();        }    }    protected void Button1_Click(object sender, EventArgs e)    {       //回传    }    private void Create()    {        Button button = new Button();        button.Text = "添加按钮";        button.Command += new CommandEventHandler(this.ButtonClick);        Panel1.Controls.Add(button);        Panel1.Visible = true;    }    public void ButtonClick(object sender, CommandEventArgs e)    {        Label1.Text = "调用事件成功!";    }





原创粉丝点击