The placeholder control can retain the position of the control dynamically added in programming mode, so as to store the dynamically added server control to the web page.
Placeholdercontrol. aspx
1 <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Placeholdercontrol. aspx. CS " Inherits = " Placeholdercontrol " %>
2
3 <! Doctype HTML public " -// W3C // dtd xhtml 1.0 transitional // en " " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
4
5 < HTML xmlns = " Http://www.w3.org/1999/xhtml " >
6 < Head runat = " Server " >
7 < Title > Placeholder control application example </ Title >
8 </ Head >
9 < Body >
10 < Form ID = " Form1 " Runat = " Server " >
11 < Div >
12 The placeholder control can retain the position of the control dynamically added in programming mode, so as to store the dynamically added server control to the web page. < BR />
13 < BR />
14 < BR />
15 < ASP: placeholder ID = " Phcontrol " Runat = " Server " > </ ASP: placeholder >
16
17 </ Div >
18 </ Form >
19 </ Body >
20 </ Html >
21
Placeholdercontrol. aspx. CS
1 Using System;
2 Using System. Data;
3 Using System. configuration;
4 Using System. collections;
5 Using System. Web;
6 Using System. Web. Security;
7 Using System. Web. UI;
8 Using System. Web. UI. webcontrols;
9 Using System. Web. UI. webcontrols. webparts;
10 Using System. Web. UI. htmlcontrols;
11
12 Public Partial Class Placeholdercontrol: system. Web. UI. Page
13 {
14 Protected Void Page_load ( Object Sender, eventargs E)
15 {
16 // Place user code here to initialize the page
17 Htmlbutton mybutton = New Htmlbutton ();
18 Mybutton. innertext = " Example 1 " ;
19 // Add button to placeholdercontrol
20 This . Phcontrol. Controls. Add (mybutton );
21
22 Mybutton = New Htmlbutton ();
23 Mybutton. innertext = " Example 2 " ;
24 This . Phcontrol. Controls. Add (mybutton );
25
26 Mybutton = New Htmlbutton ();
27 Mybutton. innertext = " Example 3 " ;
28 This . Phcontrol. Controls. Add (mybutton );
29
30 Mybutton = New Htmlbutton ();
31 Mybutton. innertext = " Example 4 " ;
32 This . Phcontrol. Controls. Add (mybutton );
33 }
34 }