且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

动态(以编程方式)添加复选框和checkedchanged事件

更新时间:2023-10-06 21:15:04

你应该做到以下几点:

  1. 为您在 foreach 循环中创建的每个 CheckBox 实例设置 ID 属性.
  2. 对于 PostBacks,请确保已创建 CheckBox,并在页面生命周期的某个时间点附加 CheckedChanged 事件处理程序在引发控件事件之前
  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