6

I'm new to using the MVP pattern and I just want to make sure on the best way to call a presenter from within a user control.

MyPage.aspx has a presenter MyPresenter

The page contains a user control which accepts MyPage's Presenter via a property which I setup from MyPage

MyUserControl.Presenter = this.Presenter

I'm now trying to call Method1 within the presenter which retrieves some config and sets it on the view from the user control.

Presenter.Method1(); // calls method and sets config to the view

My question is firstly

  1. should I be using the presenter in the user control in this way?
  2. If so, is it valid to be accessing the view value via the user control as shown below.

    Presenter.View.MyData

I just want to make sure I'm not going off down the completely wrong path with this!

Andrew
  • 9,967
  • 10
  • 64
  • 103
  • Have you read this article: http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx ? – smartcaveman Apr 04 '11 at 14:14
  • I have just had a read but still not sure that answers my question. Good read though. – Andrew Apr 04 '11 at 14:21
  • 1
    Yea, I'm not experienced enough here to be comfortable answering your question but I thought it might help. – smartcaveman Apr 04 '11 at 14:27

1 Answers1

4

What I use to do is to have one presenter for each user control which is responsible only for the user control presentation and one presenter for each page (.aspx). I think keeping things separated helps also for maintaining as you will have "skinny" presenter which are responsible only of a small section of the UI. The user control will be also "self-contained" in the way that you can reuse them as the presentation logic is kept separated from the page presentation logic.

have a look at the following post:

MVP and UserControls and invocation

Community
  • 1
  • 1
Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70
  • That's the answer I was expecting after a few chats with people - thank you for confirming :) – Andrew Apr 07 '11 at 09:24
  • Could you please answer http://stackoverflow.com/questions/8851933/event-bubbling-and-mvp-asp-net ? – LCJ Jan 16 '12 at 06:11