Dynamically (programatically) adding check boxes and checkedchanged events

前端 未结 8 509
情歌与酒
情歌与酒 2020-12-19 18:21

I am having a bit of a problem adding a few check boxes and an event handler programatically. The check boxes all appear fine, but they don\'t do anything when clicked. Does

8条回答
  •  误落风尘
    2020-12-19 18:53

    You should do the following:

    1. Set the ID property for each instance of CheckBox you create in your foreach loop.
    2. For PostBacks, ensure that your CheckBoxes are created and CheckedChanged event handler is attached at some point of the page life-cycle before control events are raised

提交回复
热议问题