Subject: Problem Extending ObjectDataSource and ObjectDataSourceVi

E

eacsub

I have an extended version for both those classes. MyObjectDataSource
overrides the GetView(string) method to return the custum view. The problem
that the my costom view doesn't get it's properties intialized like the
"SelectMethod", "DeleteMethod". they all appear as empy strings. However the
base implementation get's those properties set right.

The only reason i'm overloading the ObjectDataSourceView is that i want to
implement my own Delete method by overriding the ExecuteDelete().

Is there a way to make this work?

Thanks in advance.
 
D

Darren Clark

eacsub said:
I have an extended version for both those classes. MyObjectDataSource
overrides the GetView(string) method to return the custum view. The problem
that the my costom view doesn't get it's properties intialized like the
"SelectMethod", "DeleteMethod". they all appear as empy strings. However the
base implementation get's those properties set right.

The only reason i'm overloading the ObjectDataSourceView is that i want to
implement my own Delete method by overriding the ExecuteDelete().

Is there a way to make this work?

Thanks in advance.

I had a similar problem. The issue is really in the design of the
ObjectDataSource class. It is not well planned for inheritance.

Specifically...

The ObjectDataSource class has a private method GetView, which return the
contents of a private variable _view, creating a new ObjectDataSourceView if
necessary. The ObjectDataSource implementation of the virtual GetView(String)
method calls this private method. So far so good.

Unfortunately, everywhere else in the class also calls this private method,
not the virtual GetView(String) making the class nearly impossible to inherit
from. What will happen if you override GetView(String) yourself, is that
objects using your data source as a DataSourceControl or IDataSource will get
your view, but all calls to methods such as Select, etc will be passed onto
ANOTHER view created by the ObjectDataSource.

There are two ways around this...

1. In your GetView(String) method use reflection to find the private _view
variable and set it with your new view.
2. Inherit from DataSourceControl and implement your own data source.

Option 1 actually works pretty well, but isn't the cleanest approach. In my
case I found that it wasn't all that hard to implement a class directly
inheriting from DataSourceControl.

I do really hope this class design issue is addressed relatively soon as the
ObjectDataSource is looking to be a significant player in ASP.NET 2.0, and
it's a shame you can't effectively inherit from it.

Darren Clark
Lead Architect
Ecast, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top