Private void page_load (Object sender, system. eventargs E)
{
Button button1 = new button ();
Button1.commandargument = "B1";
Button1.text = "btn1";
Button1.command + = new commandeventhandler (this. onbutton );
Placeholder1.controls. Add (button1 );
Button button2 = new button ();
Button2.commandargument = "B2";
Button2.text = "btn2";
Button2.command + = new commandeventhandler (this. onbutton );
Placeholder1.controls. Add (button2 );
Control C3 = parsecontrol ("ASP: button id = 'button3' text = 'btn3' commandname = 'btn 'commandargument = 'b3 'runat = 'server'/>"); // convert a string to a Web Control
Control C4 = parsecontrol ("ASP: button id = 'button4' text = 'btn4' commandname = 'btn 'commandargument = 'b4 'runat = 'server'/>");
Placeholder1.controls. Add (C3 );
Placeholder1.controls. Add (C4 );
Button mybut = (button) page. findcontrol ("button3");
Mybut. Command + = new commandeventhandler (this. onbutton );
Button mybut2 = (button) page. findcontrol ("button4");
Mybut2.command + = new commandeventhandler (this. onbutton );
}
Public void onbutton (Object sender, commandeventargs E)
{
Switch (E. commandargument. tostring (). tolower ())
{
Case "B1":
Label1.text = "button 1";
Break;
Case "B2":
Label1.text = "button 2";
Break;
Case "B3":
Label1.text = "button 3";
Break;
Case "B4":
Label1.text = "button 4";
Break;
};
}
This article from "100,000 why" Computer Learning Network http://www.why100000.com