简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM