Hello,
Here is a quote from the Pro ASP.NET 2.0 in C# book (bold font from there as well):
Essentially, data binding tasks take place in this order:
1. The page object is created (based on the .aspx file).
2. The page life cycle begins, and the Page.Init and Page.Load events fire.
3. All other control events fire.
4. The data source controls perform any updates. If a row is being updated, the Updating
and Updated events fire. If a row is being inserted, the Inserting and Inserted events fire.
If a row is being deleted, the Deleting and Deleted events fire.
5. The Page.PreRender event fires.
6. The data source controls perform any queries and insert the retrieved data in the linked
controls. The Selecting and Selected events fire at this point.
7. The page is rendered and disposed.
What I found in LLBLGenProDataSource2 (an otherwise excellent control!) is that data retrieval/selection happens before Page.PreRender, which in some circumstances might cause an unnecessary data lookup. Let me explain.
I have a grid bound to said LLBLGenProDataSource2 object, which uses a TypedList as a source of data. LivePersistance is true by default and everything is fine and dandy. Server-side paging just works and everyone's happy. Now I want to add a delete button to each row in the grid. Since typed lists are read-only, I'm relying on the grid to fire Grid_RowDeleting event at which point I add custom logic to delete the appropriate entity.
Unfortunately once the page loads after the delete, I notice that the deleted item is still in the list, i.e. the data is stale. Putting the debugger and SQL Profiler to work, I find that the data source object performs the SELECT before the grid's RowDeleting event is fired and definitely before Page.PreRender.
My (hopefully) temporary fix is to set the data source's Refetch property to true, which causes another SELECT to fire, this time after Page.PreRender. So now I have made two fetches for one set of data.
Any reason for the existing event order in LLBLGenProDataSource2? Logically, I have to agree with the book - update/delete operations should all be performed prior to data retrieval, so only the final data is received.
Thanks!