Question

When using an ObjectDataSource control, either instance methods or static methods can be used for the SelectMethodand SelectCountMethod. According to the MSDN documentation, if an instance method is used, a new instance will be created and disposed upon completion.

If it is an instance method, the business object is created and destroyed each time the method that is specified by the SelectMethod property is called.

However, according to this in-depth walkthrough, if paging is enabled and both the SelectMethod and SelectCountMethod are instance methods, the same instance is used when calling these methods.

If we have enabled paging and our SelectMethod and SelectCountMethod are instance methods, the same instance is used when calling both methods, so we can save the total number of registers in a field in the SelectMethod and then we can return it in the SelectCountMethod.

In another reference, the information provided (apparently by a member of the MS ASP.NET team) contradicts the information above.

However you should realize that different instances are used to call the Select and SelectCount method ...

My question: Which of these behaviors is the actual one implemented in asp.net? Is the same instance used when calling those methods, or are they called by different instances?

I have attempted (in .net 3.5 VS 2008) to implement paging using the first reference (which says they are called by the same instance), and it does work for me. When I set the record count into a non-static variable/field in the SelectMethod, the same value is indeed returned when SelectCountMethod is called. I suppose that should mean that the same instance is used, contrary to the information in the second reference, and that it would be safe for me to set the record count in the SelectMethod and return it in the SelectCountMethod using a non-static variable. However, I'd prefer if someone could actually confirm this, as the first reference is quite old (written in 06), and I have no way of testing if this behavior has been changed in newer versions (.net 4.0 and up).

Please let me know if my question is unclear, or if there is an official reference that can answer my question.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top