I have a c# web application where I need to dynamically generate controls, and where the actions on the controls also affect which controls will be rendered. Imagine for example a list of buttons, where each button should remove itself (and its reference in the database). I have the feeling I don't understand something quite basic here (at least it should be)
I would like to use event handlers here. However, the question is then where should I generate the controls, in Page_Load or PreRender? If I generate them in page_load the event handlers haven't fired yet so the generated content isnt up to date yet. I can also generate it in PreRender but then the event handlers don't fire because the controls dont exist yet.
What would be the preferred way of handling this? I really want to avoid the option to modify the generated content later, it is way too error-prone in my case. I would like to generate all content from scratch, right after the events have been handled. Currently I solve this partially by examining the request.form before the generation of the controls but I have quite a lot of actions and it's not really a workable solution in quite some cases already.