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

Discussion in 'ASP .Net' started by Dave A, Nov 27, 2007.

  1. Dave A

    Dave A Guest

    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
    Dave A, Nov 27, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    1
    Views:
    416
    S. Justin Gengo
    Aug 3, 2003
  2. Replies:
    0
    Views:
    428
  3. =?Utf-8?B?Ti4gU2hlaHphZA==?=

    change of session does not fire button click event for second time

    =?Utf-8?B?Ti4gU2hlaHphZA==?=, Apr 4, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,039
    Scott Allen
    Apr 5, 2005
  4. jobs
    Replies:
    0
    Views:
    1,602
  5. Replies:
    3
    Views:
    983
Loading...

Share This Page