Last post Sep 21, 2012 05:01 AM by riestra
Sep 21, 2007 01:47 AM|shekhar_249|LINK
I'm using gridview with ObjectDataSource on my page ,I have enabled default paging for grid and ODS.
The problem m facing is on page load select method for ODS is getting called twice .
how to restrict auto call to this method of ODS? Your help is really appreciated.
Sep 21, 2007 05:51 AM|maheshsingh|LINK
I think you are calling Objectdatasource twice
Please check might be you are pouting your ODS some where which fires twice.
Please paste your code
Sep 25, 2007 12:25 AM|Nai-Dong Jin - MSFT|LINK
From your description, it seems that you’re worried about the duplicated invoking of select method in ObjectDataSource while postback occurs, right?
Actually, you don’t need to worry about the performance issue, since ObjectDataSource has its own cache mechanism. The ObjectDataSource control's cache is maintained internally, and the cache is created and used during the Select method of the ObjectDataSource,
which means, when ObjectDataSource.Select method is called, it will check the cache to see whether it should use cache or re-execute the query from the underlying data access class. What you should do is just to make sure if the ObjectDataSource control has
data caching enabled.
Oct 25, 2007 08:16 PM|petermeadit|LINK
So the data caching is disabled by default?
It was not enabled so I enabled it, however now when i call the select method it will not call it , then I turn off data caching and it will call the select method when I specify plus it will call it again at the end of Page_Load
so it seems ObjectDataSource1.EnableCaching = true; does not work how i thought it would.
Dec 11, 2007 04:16 AM|shekhar_249|LINK
yes. data caching is disabled
Dec 28, 2007 05:56 AM|shekhar_249|LINK
I Think i got the solution to this problem..
there may be cases in which ODS will call select method twice:
When we are hiding/showing gridview column dynamically in code
When you are accessing different class/assembly method in aspx page
Sep 15, 2009 04:14 AM|MaximusDecimus|LINK
It works fine for me.
Thanks for your tip off.
Feb 12, 2010 06:55 AM|hmnt05|LINK
Great tip .. ODS Caching does it all but it fails to respond to the Sort-event.
Here, I got this thread which explains the issue and I've got some URLs which provide a promising fix -
Let me know if there's a better or easier way to handle this!
PS: Some other imp facts about ODS caching to be conscious about -
object data source paging sorting gridview caching
Feb 15, 2010 04:29 AM|hmnt05|LINK
Here's my original problem which lead me to this thread -
I've found some other references like:
But all say that I've to perform sorting on app side using the 'Custom-sort' (that is add extra methods to enable sorting on a generic collection of objects). This solution was not acceptable because it demanded that I pull ALL the records from the DB and
then perform sorting on them!
Firstly, I don't believe app can do better/faster sorting then DB. And secondly - this ruins the whole performance benefit that I'm getting due to optimized pagination - I'm using .skip() and .take() LINQ methods to fetch only a 'pageful' of records.
Well, finally I had to invent a fix of my own. It might be limited to my kind of scenario but for sure its much easier and also preserves the optimization of both pagination as well as data-caching.
I've tapped the Gridview's 'Sorting' event. The 'custom-sort' error triggers if I allow the ODS to try to do the sorting on its own on the cached data. Instead of that, now I perform sorting manually and cancel the sorting-event.
For this - I just have to make the 'orderBy' parameter explicit in ODS and set it to the new sort-expression in Gridview's 'Sorting' event. This will refresh the Grid and at the end I do:
odsOrganization.SelectParameters["orderBy"].DefaultValue = GetSortExpr(e.SortExpression);
e.Cancel = true;
- this tells the ODS to cancel sorting (which I already performed before canceling the event - as above). ITs like I'm cheating the ODS and handling the sorting in background. And thanks to ODS that it senses that the 'SelectParameters["orderBy"]' has changed
and performs a select once again. I The previous sort automatically gets stored in the 'odsOrganization.SelectParameters["orderBy"].DefaultValue' which I can use in sub-sequent iterations.
I'm still testing this one but its amazing that just by updating the parameter's DefaultValue ODS goes back to fetch the data. This preserves the cache until the user performs sort (it takes data from cache for other operations) and goes back to the
DB to sort. Hope its going to work for me!
Sep 21, 2012 05:01 AM|riestra|LINK
Private Sub ObjectDataSourceLogic_Selecting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSourceLogic.Selecting
If e.ExecutingSelectCount <> True Then
e.InputParameters("params") = params()
This way the code doesn't execute twice
This event can be fired twice for a single call to the
Select method, if the
SelectCountMethod property is set. The
ExecutingSelectCount property of the
ObjectDataSourceSelectingEventArgs object is used to determine if select was called to retrieve data or retrieve the count.