Asp. NET in the use of placeholder controls _ basic Application

Source: Internet
Author: User

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);

Related Article

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.