Dynamically change custom components!

Source: Internet
Author: User
1. Put a container PlaceHolder on the leaf.
2. You can dynamically load the required custom components or user components in the container.
Example:
Add a TextBox to the container, and then return it to the Button.
The code is as follows:
Protected System. Web. UI. WebControls. PlaceHolder PlaceHolder1;
Protected System. Web. UI. WebControls. Button Button1;

Private void Page_Load (object sender, System. EventArgs e)
{
If (! IsPostBack)
{
TextBox t = new TextBox ();
T. Text = "loading for the first time ";
PlaceHolder1.Controls. Add (t );
}
}
Private void button#click (object sender, System. EventArgs e)
{
PlaceHolder1.Controls. Clear ();
Button B = new Button ();
B. Text = "Xinyu building ";
PlaceHolder1.Controls. Add (B );
}
Running effect: the first time you put a TextBox
Click the button to change

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.