Re-databinding after user control change event - missing viewstate second time.

D

Dave A

I have a user control that is dynamically loaded into a repeater; (so the
user control appears several times)



The user control features a text box and a delete button. When the delete
button is clicked the usercontrol raises an event indicating that the data
in the database that relates to this user control is to be deleted.



In the parent page, when a change in the user control is detected, the
repeater's data binding has to be called again so as to refresh the screen -
and this is where the wheels fall off.



Each user control is effectively dynamically loaded twice; once during
OnInit and then once during the user control's OnChange event handler. On
the second load, the user control's controls do not have the viewstate
reloaded; either because it was previously loaded or because it is happening
too late in the page lifecycle.



In any case, any text that was previously entered into any of the text boxes
vanishes.



If there is another button in the user control that just does a postback
(and does not re-call the Databinding) then the text in the text boxes is
preserved as expected.



A very simple example can be downloaded from
www.tcpiq.com/temp/doubleloading.zip (screen shot at
www.tcpiq.com/temp/doubleloading.jpg). The Delete button as described above
is replaced with the 'Redatabind this repeater' button. Place text any
text box and click 'just post back' and it remains but clicking 'Rebind this
repeater' then it disappears.



Please not that this example is a very simplified example of the real
problem. In the real problem not having the appearance of the controls
preserved between postbacks produces some highly undesirable behaviour.
(think nuclear missiles being launched, etc)



How have people solved this problem?



Is there a Page.ReLoadControlAndReloadAllViewStateSettingPlease(@"~\MyUserControl1.ascx")
method that I have not found?



Can you force a user control to reset its state from the viewstate?



Thanks in advance



Dave A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top