views:

273

answers:

1

I've just started using the MVP pattern in the large ASP.NET application that I'm building (re-building actually) and I am having a hard time figuring out how I should be using Events applied to the view.

Say I have 2 drop down lists in a User Control, where one is dependent on the other's value:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ucTestMVP.ascx.vb" Inherits=".ucTestMVP" %>    
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="True" />
<asp:DropDownList ID="ddlCity" runat="server" />

How should should the AutoPostBack Event be defined in the interface? Should it be an event that is handled by the User Control like this:

Public Partial Class ucTestMVP
  Inherits System.Web.UI.UserControl
  Implements ITestMVPView

  Protected Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
      Dim presenter As New TestMVPPresenter(Me)
      presenter.InitView()
    End If
  End Sub

  Private Sub ddlCountrySelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
    Dim presenter as New TestMVPPresenter(Me)
    presenter.CountryDDLIndexChanged()
  End Sub

End Class

Or should there be an event defined at the Interface? If this is the preferred pattern, how do I add events to be handled and used?

+2  A: 

I don't know if there's a universally preferred pattern. I tend to prefer adding the event to the view interface and having the presenter respond to the view. I described this pattern in more detail here.

Haacked