代碼如下:
1 private TextBox Txt;
2
3 protected void Page_Load(object sender, EventArgs e)
4
5 {
6
7 Create();
8
9 }
10
11 private void Create()
12
13 {
14
15 Button Btn = new Button();
16
17 Btn.ID = "MyBtn";
18
19 Btn.Text = "顯示";
20
21 Btn.CommandArgument = "MyBtn";
22
23 Btn.Command += new CommandEventHandler(this.MyBtn_Command);
24
25 this.Txt = new TextBox();
26
27 this.Txt.ID = "MyTxt";
28
29 this.FindControl("form1").Controls.Add(Btn);
30
31 this.FindControl("form1").Controls.Add(Txt);
32
33 //這裡還可以寫成:Page.Form.Controls.Add(Txt);
34
35 }