Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Model-View-Presenter and GridView via ObjectContainerDataSource Control

A little before and right after the Tampa CodeCamp I took about 10 days off to do some work around the house as well as hang with the kids at the beach, so I am a bit late with this post regarding the Tampa CodeCamp.

I posted my Tampa CodeCamp presentation slides on the Web Client Software Factory on the PnPGuidance Website. The sample code showing off the WCSF with Enteprise Library is there, too.

I received a question via email about the value of the ObjectContainerDataSource Control in my example. The ObjectContainerDataSource Control is a custom DataSource Control provided by the Patterns & Practices Team in the WCSF that is Model-View-Presenter Friendly.

If you think about the ObjectDataSource Control that is provided in System.Web, it requires and calls a type typically in the business logic layer that implements select, insert, update, and delete methods. When implementing Model-View-Presenter, however, you want the View to delegate events to the Presenter Class where it will respond to any UI events. The ObjectContainerDataSource Control makes this possible by publishing events that can then be easily delegated to the Presenter Class.

Here are some code snippets from the sample code available for download mentioned above:


protected void Page_Init(object sender, EventArgs e)
// CustomerDataSource is an ObjectContainerDataSource
CustomerDataSource.Inserted += new EventHandler(CustomerDataSource_Inserted);

void CustomerDataSource_Inserted(object sender, ObjectContainerDataSourceStatusEventArgs e)
_presenter.OnInsert((Customer) e.Instance);


Notice how you can just subscribe to the insert, update, delete, and select events of the ObjectContainerDataSource Control and then pass those events to the Presenter Class. This is a lot more Model-View-Presenter Friendly than your normal ObjectDataSource Control. Note that passing the Customer Instance to the Presenter in the OnInsert Method is purely optional. Most people prefer that the Presenter Class request the Customer Instance separately.

Just thinking out loud here, but I wonder if the Patterns & Practices Team can do something that gives us a Model-View-Presenter Friendly LinqDataSource Control as well. Hmm….

This entry was posted in Featured. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

2 Responses to Model-View-Presenter and GridView via ObjectContainerDataSource Control

  1. David Hayden says:


    I have created Views both ways, using events or delegation, and both work fine. I haven’t come across an argument for using one over the other so far with webforms.

    Since the Web Client Software Factory uses the delegation route as opposed to events, I just normally use that method when working with it.

    Either is fine and the ObjectContainerDataSource Control will work both ways.

  2. Lance Harper says:

    I like what you did with the ObjectDataSource control. What do you think about adding events to your view interfaces instead? And then your presenter objects could subscribe to said events decoupling your view layer from the presentation layer leaving very “dumb” views?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>