By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

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

P: n/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.ReLoadControlAndReloadAllViewStateSettingPlea se(@"~\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


Nov 27 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.