Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic button click event

Status
Not open for further replies.

euntair

Programmer
Sep 13, 2007
53
US
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);
}

void one_Click(Object sender, EventArgs e){
string test = "one";
}
void two_Click(Object sender, EventArgs e) {
string test = "two";
}
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top