Creating a Custom ObjectDataSource Control

If you discover that you are declaring an ObjectDataSource control with the same properties on multiple pages, it makes sense to derive a new control from the ObjectDataSource control that has these properties by default. That way, you can simply declare the derived control in a page.

For example, if you display a list of movies in multiple pages in your website, it would make sense to create a specialized MovieDataSource control.

The control in Listing 18.40, named the MovieDataSource control, derives from the base ObjectDataSource control class. The MovieDataSource control represents the MoviesComponent, which is also contained in Listing 18.40.

Listing 18.40. MovieDataSource.cs

The MovieDataSource ...

Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.