Author: scott_rider | Posted on: 11/3/2008 5:14:05 AM | Views : 325

How do I link a click event to a button that is created in code behind? What I have below is what makes sense atm, but gives me a "Value cannot be null. Parameter name: child" error. What am I missing?

using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;


public partial class _Default : System.Web.UI.Page {
protected HtmlInputButton one;
protected Button two;

private void InitializeComponent(){
this.one = new HtmlInputButton();
this.one.ID = "one";
this.one.Value = "One";
this.one.ServerClick += new EventHandler(this.one_Click);

this.two = new Button();
this.two.ID = "two";
this.two.Text = "Two";
this.two.Click += new EventHandler(this.two_Click);
}

protected void Page_Load(object sender, EventArgs e) {
form1.Controls.Add(this.one);
form1.Controls.Add(this.two);
...

Go to the complete details ...