You can use the placeholder control to place an empty container control in a Web page, and then dynamically add, delete, or traverse each child element at run time. The control renders only its child elements, and there is no HTML-based output itself.
You can add any HTML controls, even JavaScript code, to placeholder during the actual use.
Use the placeholder control as a container for storing server controls that are dynamically added to a Web page. The placeholder control does not produce any visible output and can only be used as a container for other controls on the Web page. You can use the Control.Controls collection to add, insert, or remove controls from the placeholder control.
One, placeholder dynamically add controls
Front desk:
Copy Code code as follows:
<asp:placeholder id= "PlaceHolder1" runat= "Server" ></asp:PlaceHolder>
Background:
Copy Code code as follows:
button btnnew=new buttons ();//Declare a new one
Btnnew.text = "New Button";
PLACEHOLDER1.CONTROLS.ADD (btnnew);//Add to control
Literal litnewhtml = new Literal ()//Add <br/> <p> or Normal text use this method
Litnewhtml.text = "<p> I am a section of HTML code </p>";
PLACEHOLDER1.CONTROLS.ADD (litnewhtml);
Ii. placeholder dynamically add Web user controls
Create Test.ascx write code as follows:
Copy Code code as follows:
<div>
I'm the content of the Test.ascx control.
</div>
To create a separate winform1.aspx page:
Front desk:
Copy Code code as follows:
<asp:placeholder id= "PlaceHolder1" runat= "Server" ></asp:PlaceHolder>
Background:
Copy Code code as follows:
PlaceHolder1.Controls.Clear (); Clear all controls
Control test = Page.LoadControl ("~/test.ascx");
PLACEHOLDER1.CONTROLS.ADD (test);