M
Matt Weber
Brief background: I have a page that loads n UserControls into a PlaceHolder
control, where n corresponds to a number of inputs by the user. Each
UserControl consists of a couple of labels, a TextBox, an ImageButton, and a
DataGrid.
I'm trying to fire an event from within the UserControl to notify the page
that it sits on that the UserControl needs to be deleted. The event is fired
when the user clicks on the ImageButton that resides within my UserControl.
This works just fine. However, after the page is loaded again sans the
deleted control, none of the ImageButtons retain their Click event handler.
If the ImageButton is clicked I get a postback, and then the event handlers
get hooked up again. So essentially, after deleting the first control, the
ImageButton has to be clicked twice to delete any subsequent control.
Furthermore, if the controls being deleted are the last ones within the
PlaceHolder, everything works fine. The problem only occurs when deleting a
control that is not last within the PlaceHolder.
Within the page I am sessioning information to reload the previously loaded
UserControls into the PlaceHolder on page load. Thus, when the delete event
is fired, all of the controls on the page are reloaded into the PlaceHolder
(including the control I'm going to delete). The control to delete is then
removed from the PlaceHolder and my session data, and then the PlaceHolder is
reloaded with the remaining controls.
I've noticed that, because I'm loading the controls on postback, then
clearing the PlaceHolder control and reloading all but the deleted control,
the control prefixes for the UserControls within the PlaceHolder do not start
at zero. This makes sense, because the UserControls are being loaded twice,
but it seems like it might be part of the reason my events are being
disconnected.
Thanks for reading.
Any thoughts?
control, where n corresponds to a number of inputs by the user. Each
UserControl consists of a couple of labels, a TextBox, an ImageButton, and a
DataGrid.
I'm trying to fire an event from within the UserControl to notify the page
that it sits on that the UserControl needs to be deleted. The event is fired
when the user clicks on the ImageButton that resides within my UserControl.
This works just fine. However, after the page is loaded again sans the
deleted control, none of the ImageButtons retain their Click event handler.
If the ImageButton is clicked I get a postback, and then the event handlers
get hooked up again. So essentially, after deleting the first control, the
ImageButton has to be clicked twice to delete any subsequent control.
Furthermore, if the controls being deleted are the last ones within the
PlaceHolder, everything works fine. The problem only occurs when deleting a
control that is not last within the PlaceHolder.
Within the page I am sessioning information to reload the previously loaded
UserControls into the PlaceHolder on page load. Thus, when the delete event
is fired, all of the controls on the page are reloaded into the PlaceHolder
(including the control I'm going to delete). The control to delete is then
removed from the PlaceHolder and my session data, and then the PlaceHolder is
reloaded with the remaining controls.
I've noticed that, because I'm loading the controls on postback, then
clearing the PlaceHolder control and reloading all but the deleted control,
the control prefixes for the UserControls within the PlaceHolder do not start
at zero. This makes sense, because the UserControls are being loaded twice,
but it seems like it might be part of the reason my events are being
disconnected.
Thanks for reading.
Any thoughts?