When creating controls dynamically…

Nice article on “The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.”


… if you are assembling a hierarchy of controls to build a Table you will follow this sequence:

Create instance of a Table control
Create an instance of TableRow
Create one or more instances of TableCell
Create and add controls to your TableCell Controls collection
Add those TableCell instances to the TableRow Cells collection
Add the TableCell to the Table Rows collection

Now that you have already added the TableCell instances to the Rows collection you cannot add more controls to it at this point. That would result in the above error. Internally the ASP.NET engine must be firing the databinding or other events listed in the error message. Fair enough, I can carefully add things in the right order.

Now my next puzzle. I am still not fully understanding when I should create instances. I have the declarati

CheckBoxList Validation in ASP.Net – Required Field Validator