Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web Forms - Model View Presenter and user controls

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!

like image 947
Andrew Avatar asked Apr 04 '11 13:04

Andrew


1 Answers

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

like image 93
Massimiliano Peluso Avatar answered Oct 15 '22 06:10

Massimiliano Peluso