How do I get many, but not all, property values from View to Presenter in WebFormsMvp?

Posted by andrej351 on Stack Overflow See other posts from Stack Overflow or by andrej351
Published on 2010-06-11T07:20:15Z Indexed on 2010/06/11 7:22 UTC
Read the original article Hit count: 327

Hey there,

What is the best way to get a number of property values of a business object from the View to the Presenter in a WebFormsMvp page?

Here is what i propose:

The scenario is, I have a business object called Quote which i would like to load form the database, edit and then save. The Quote class has heaps of properties on it. The form is concerned with about 20 of these properties. I have existing methods to load/save a Quote object to/from the database. I now need to wire this all together.

So, in the View_Load handler on my presenter i intend to do something like this:

public void View_Load(object sender, EventArgs e)
{
    View.Model.Quote = quoteService.Read(quoteId);
}

And then bind all my controls as follows:

<asp:TextBox ID="TotalPriceTextBox" runat="server"
    Text="<%# Model.Quote.TotalPrice %>" />

All good, the data is on the screen.

The user then makes a bunch of changes and hits a "Submit" button. Here is where I'm unsure.

I create a class called QuoteEventArgs exposing the 20 properties the form is able to edit. When the View raises the Submit button's event, I set these properties to the values of the controls in the code behind. Then raise the event for the presenter to respond to. The presenter re-loads the Quote object from the database, sets all the properties and saves it to the database.

Is this the right way to do this? If not, what is?

Cheers, Andrej.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about webforms