Placeholder control application example

Source: Internet
Author: User
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 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.