custom control viewstate problem

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
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top