asp.net dynamically add a checkbox and event

Source: Internet
Author: User

Learn how to dynamically add button and events to a panel.
Simple demo dynamic Add Picture button and add Click event

ImageButton jian = new ImageButton ();
            Jian. IMAGEURL = "~/picture01.png";
            Jian. Click + + new Imageclickeventhandler (Jian_click);
            P.controls.add (Jian);

Then ran into the checkbox, thought it should be similar, but wrote the following code did not react

CheckBox Cbox = new checkbox ();
            Cbox. Checked = true;
            Cbox. Checkedchanged+=cbox_change;
            P.controls.add (Cbox);

Look at a lot of resources on the Internet and finally found the reason. This event happened on the server side, and after we clicked the checkbox and did not return the value of the change back to the server, the modifications are as follows:

CheckBox Cbox = new checkbox ();
            Cbox. Checked = true;
            Cbox. AutoPostBack = true; Added this sentence
            Cbox. Checkedchanged+=cbox_change;
            P.controls.add (Cbox);

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.