Monday, March 12, 2012

How to handle multiple UserControls that manipulate the same underlying data?

How should I handle the sitaution where two or more UserControls on the same page are using ObjectDataSources that leverage the same business object?

For example, UserControlA and UserControlB are both using BusinessObjectA via their respective ObjectDataSource. However, there does not appear to be a guarentee that UserControlA's events (i.e., DELETing data) fire before UserControlB's events (i.e., SELECTing data.) The result is that UserControlB can (and does) display incorrect data for the page, as it performed its SELECT before UserControlA performed its DELETE.

The situation that I find myself in at the moment is a page made up of GenericWebParts via dragging these UserControls into a WebPartZone. The controls are designed to be independant of one another, hence the reason why they each have their own ObjectDataSource. The problem is arising just as described above ... when I delete data via one UserControl, another UserControl on the page that makes decisions based upon the same data does not see the changes until a forced page refresh.

I did a little digging into this tonight and sure enough, UserControlB is being loaded before the events for UserControlA are firing, resulting in UserControlB read data before UserControlA has a chance to delete it.

I'm able to hack the solution by performing the delete opeartion from another page. So instead of enabling deletes via UserControlA's GridView, I've added a Hyperlink Field to ControlA's GridView which calls a Delete.aspx and then redirects back to the default page. However, this does not feel very clean at all.

Labels: , , , , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home