1private void Page_Load(object sender, System.EventArgs e)
2 {
3 Control c3 = ParseControl("<asp:Button id='Button3' text='Btn3' commandname='Btn' commandargument='b3' runat='server' />");
4 Control c4 = ParseControl("<asp:Button id='Button4' text='Btn4' commandname='Btn' commandargument='b4' runat='server' />");
5 PlaceHolder2.Controls.Add(c3);
6 PlaceHolder2.Controls.Add(c4);
7 Button myBut = (Button)Page.FindControl("Button3");
8 myBut.Command += new CommandEventHandler(this.OnButton);
9 Button myBut2 = (Button)Page.FindControl("Button4");
10 myBut2.Command += new CommandEventHandler(this.OnButton);
11 }
12 public void OnButton(Object Sender, CommandEventArgs e)
13 {
14 switch (e.CommandArgument.ToString().ToLower())
15 {
16 case "b0":
17 Label1.Text = "Button 0";
18 break;
19 case "b1":
20 Label1.Text = "Button 1";
21 break;
22 case "b3":
23 Label1.Text = "Button 3";
24 break;
25 case "b4":
26 Label1.Text = "Button 4";
27 break;
28 };
29 }
30
2 {
3 Control c3 = ParseControl("<asp:Button id='Button3' text='Btn3' commandname='Btn' commandargument='b3' runat='server' />");
4 Control c4 = ParseControl("<asp:Button id='Button4' text='Btn4' commandname='Btn' commandargument='b4' runat='server' />");
5 PlaceHolder2.Controls.Add(c3);
6 PlaceHolder2.Controls.Add(c4);
7 Button myBut = (Button)Page.FindControl("Button3");
8 myBut.Command += new CommandEventHandler(this.OnButton);
9 Button myBut2 = (Button)Page.FindControl("Button4");
10 myBut2.Command += new CommandEventHandler(this.OnButton);
11 }
12 public void OnButton(Object Sender, CommandEventArgs e)
13 {
14 switch (e.CommandArgument.ToString().ToLower())
15 {
16 case "b0":
17 Label1.Text = "Button 0";
18 break;
19 case "b1":
20 Label1.Text = "Button 1";
21 break;
22 case "b3":
23 Label1.Text = "Button 3";
24 break;
25 case "b4":
26 Label1.Text = "Button 4";
27 break;
28 };
29 }
30