Is it better to perform data access operations on the page and then populate the properties of each usercontrol with the retrieved data.
–OR–
Is it better if each UC calls the business layer and pulls its own data independently without having to depend on the page.
Existing Conditions:
1. Any information (Querystring, URL, etc) that the page would use for data access is also available to the individual UC’s
2. Both solutions utilize caching.
My coworker insists that the first option is better since Data access only happens once on the page.
The second option seems more logical to me since it will allow me to place the UC on another page without the need for any additional wiring on the page itself. The page and the UC are truly decoupled.
Please advise on why one would be better than the other.
The first option is the better in most cases.
A UserControl is not the controller but the page. It should display data not access it. The page normally sets the UserControl’s properties.
One of it’s purpose is reusability. This will be decreased if it’s hardlinked with datasources. It should work with any kind of DAL, it shouldn’t bother with them at all.
But if it’s only purpose is encapsulation(f.e. as container control used in a TabContainer’s TabPanel) a UserControl is a page replacement, hence does also the data access and event handling. You wouldn’t reuse this kind of UserControl often.