Custom User Control in ASP.Net has its state lost between postbacks

67 views Asked by At

I have a Web User Control which I have developed to represent a company object and the services the company is subscribing to. The control has a public property CompanyId which the host page sets. When the property is set, the control connects to the BLL and retrieves the company details and a list of services the company is subscribing to. It then populates the various textboxes for the details. For the services, I use a CheckBoxList control which I create (from all available services) and loop through the company services checking off the ones the company is subscribing to.

The control also has a Save() method which causes all values in the textboxes to be saved. For the services, I am looping through all checkboxes and create/delete service subscriptions from the DB accordingly.

When I set the CompanyId (by selecting from a grid on the host page), the control populates all fields as it should. However when I call the Save method, all textbooks are saved fine, but the CheckBoxList has no items, and therefore no subscriptions get saved. It looks like the CheckBoxList control is losing its items when I post back. I should note here that the Page_Load event is not used to set anything; as already mentioned I am setting values when the CompanyId property changes.

Any ideas? I would appreciate any help on this...

0

There are 0 answers