K
Klaus Jensen
Subject: Handling events of controls created at runtime
I need to render some buttons at runtime based on a database, tie events to
them, and handle the events when they fire.
In Page_Load I create the controls (for example a delete-button), add them
to a placeholder, add eventhandlers, and the controls are displayed as
expected.
I click the button, the event fires as I wanted, I delete a record in the
database, and now I want to re-render the entire thing to reflect the
changes in the database.
This is where my problems start...
If I clear the placeholder and render the buttons/controls again, the
eventhandlers work. I click a button, no event is fired.
I currently work around this by response.redirecting to the page again - and
this created an illusion of what I want, but is not the right way to handle
this.
Please note, that this is a simplified example - obviously there was no need
to generate controls at runtime, if it could be solved by using a datagrid
or something like that.
I need to render some buttons at runtime based on a database, tie events to
them, and handle the events when they fire.
In Page_Load I create the controls (for example a delete-button), add them
to a placeholder, add eventhandlers, and the controls are displayed as
expected.
I click the button, the event fires as I wanted, I delete a record in the
database, and now I want to re-render the entire thing to reflect the
changes in the database.
This is where my problems start...
If I clear the placeholder and render the buttons/controls again, the
eventhandlers work. I click a button, no event is fired.
I currently work around this by response.redirecting to the page again - and
this created an illusion of what I want, but is not the right way to handle
this.
Please note, that this is a simplified example - obviously there was no need
to generate controls at runtime, if it could be solved by using a datagrid
or something like that.