L
Lachlan James
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
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