custom control viewstate problem

Discussion in 'ASP .Net Web Controls' started by Lachlan James, Jan 5, 2005.

  1. Hello,

    I have a custom control (extends WebControl and implements
    INamingContainer) that is bound & added to the page
    dynamically in the Page_Load method. The control is also
    rebound again when I handle a click event for a button on
    that same page.

    This means that potentially the control is added & bound
    inside the Page_Load, then again when the datasource
    changes in the click event handler.

    Not that I must re-add the controls each time in the
    Page_Load otherwise they disappear because they are
    dynamically added.

    That seems straight forward, but for some reason the
    ViewState for the control is lost when the control is re-
    bound & re-added in the click event handler. The custom
    control has a property which it stores in ViewState, but
    this gets re-set when it is re-bound & re-added.

    Correct me if I am wrong but I thought the purpose of
    viewstate is to persist data across postbacks, why would
    this property be reset when I re-bind and re-add it to the
    page inside the click event handler?

    Thanks, Lachlan
    Lachlan James, Jan 5, 2005
    #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. Walter
    Replies:
    0
    Views:
    318
    Walter
    Oct 11, 2006
  2. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  3. Josema
    Replies:
    2
    Views:
    336
  4. whoisnidhee

    ViewState of the Composite Control composed of custom control

    whoisnidhee, Jul 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    312
    Nidhee
    Jul 16, 2004
  5. Josema
    Replies:
    0
    Views:
    197
    Josema
    May 9, 2005
Loading...

Share This Page