S
Stephan B
Hi, for some reason I cannot find my yesterdays post, so here is an
other try. I have got some Dynamic User Controls (UC's) on my page.
The user can add as many as he likes by clicking a button. This all
works fine. Every UC has also a button to remove itself from the page.
Here is were the trouble starts. I can remove the control by using the
remove function of the placeholder on which the control is situated. I
also keep track of the number of controls in this placeholder by using
an arraylist containing the ID's of the control. Of course, I also
remove the control from this arralist. I know that on every postback I
have to recreate the control and there is the problem. Because the
delete event fires after the page_load. So on a postback the deleted
control shouldn't be there nomore. But removing it from the
collection, doesn't remove it from the viewstate. So, when I build my
page again. There are viewer controls, but the the content of the
textboxes (which are on my UC) isn't right anymore. i.e. let's say I
have 4 UC on my page (all created dynamically by a buttonclick)
UC 1 with a textbox. Value = aa
UC 2 with a textbox. Value = bb
UC 3 with a textbox. Value = cc
UC 4 with a textbox. Value = dd
Now, if I remove let say UC 3. This works fine. There are only 3 UC's
left.But if I remove an other control for example UC 2, the page show's
up with again 3 UC's. UC1 with the right value and UC 4 with the right
value + an empty UC. The longer the list of UC's becomes the stanger
the behavior. I have been struggeling for twee weeks now, but know one
seems to have the right answer. I read all about page life-cicles,
viewstate. The only conclusion I have right now is that when I remove
the UC from a collection, it isn't removed from the viewstate (on
postback). The viewstate keeps the orginial ID from the Controls, so
when removing UC 3 (with an internal ID of _Ctrl2, on a postback the
last element of these controls, which is UC 4 with _Ctrl3 is removed.
So it builds up 3 controls, but not the right ones. Does anybody have
an idea. I can post some code, but it's a lot. Thats because I use
nested controls to make is "easier".
other try. I have got some Dynamic User Controls (UC's) on my page.
The user can add as many as he likes by clicking a button. This all
works fine. Every UC has also a button to remove itself from the page.
Here is were the trouble starts. I can remove the control by using the
remove function of the placeholder on which the control is situated. I
also keep track of the number of controls in this placeholder by using
an arraylist containing the ID's of the control. Of course, I also
remove the control from this arralist. I know that on every postback I
have to recreate the control and there is the problem. Because the
delete event fires after the page_load. So on a postback the deleted
control shouldn't be there nomore. But removing it from the
collection, doesn't remove it from the viewstate. So, when I build my
page again. There are viewer controls, but the the content of the
textboxes (which are on my UC) isn't right anymore. i.e. let's say I
have 4 UC on my page (all created dynamically by a buttonclick)
UC 1 with a textbox. Value = aa
UC 2 with a textbox. Value = bb
UC 3 with a textbox. Value = cc
UC 4 with a textbox. Value = dd
Now, if I remove let say UC 3. This works fine. There are only 3 UC's
left.But if I remove an other control for example UC 2, the page show's
up with again 3 UC's. UC1 with the right value and UC 4 with the right
value + an empty UC. The longer the list of UC's becomes the stanger
the behavior. I have been struggeling for twee weeks now, but know one
seems to have the right answer. I read all about page life-cicles,
viewstate. The only conclusion I have right now is that when I remove
the UC from a collection, it isn't removed from the viewstate (on
postback). The viewstate keeps the orginial ID from the Controls, so
when removing UC 3 (with an internal ID of _Ctrl2, on a postback the
last element of these controls, which is UC 4 with _Ctrl3 is removed.
So it builds up 3 controls, but not the right ones. Does anybody have
an idea. I can post some code, but it's a lot. Thats because I use
nested controls to make is "easier".