English 中文(简体)
活动 Bubbling and MVP: ASP。 NET
原标题:Event Bubbling and MVP: ASP.NET

我正试图学习无国界医生组织。

它正在协会中使用网络形式。 NET。 我有两个用户控制了当前电文。 本期 观点显示时间。 有一个文本箱来增加控制中的天数。 新到的日期称为“到期日”。 当 but子被点上加日时,会发生“MyBtnAddDaysClickedEvent”事件。

在《意见》中,有一个标志,显示“相应日期”。 目前,我正在为变数的“月数月数”(因为我不知道如何适当做)。 How do I set the Value for个月的Value ToPasss changing to it compliance with MVP model?

string monthValueToPass = "TEST";
monthPresenter.SetMonth(monthValueToPass);

www.un.org/Depts/DGACM/index_spanish.htm 期望的是建立便于进行单位测试的微型项目,并且不违反MVP的等级。

注:虽然这是一个简单的例子,但我期待利用MVP和验证机制,对GridView控制中具有约束力的数据作出回答。

注:可以认为完全依赖介绍者?

注:每个用户的控制在这里是单独的看法。

注:对同一发言者有多种看法(例如,根据宽恕对不同用户的不同控制?)

GUIDELINES

  1. http://forums.asp.net/t/1760921.aspx/1?Model+View+Presenter+Guidelines”rel=“nofollow noreferer”>Model View Presenter - Guidelines

------

using System;
public interface ICurrentTimeView
{
    //Property of View
    DateTime CurrentTime 
    {
        set; 
    }
    //Method of View
    void AttachPresenter(CurrentTimePresenter presenter);
}

using System;
public interface IMonthView
{
    //Property of View
    string MonthName 
    {
        set; 
    }

    //Method of View
    //View interface knows the presenter
    void AttachPresenter(MonthPresenter presenter);     
}

using System;
public class CurrentTimePresenter 
{
    private ICurrentTimeView view;

    //Constructor for prsenter
    public CurrentTimePresenter(ICurrentTimeView inputView) 
    {
        if (inputView == null)
        {
            throw new ArgumentNullException("view may not be null");
        }
    }
    this.view = inputView;
}

//Method defined in Presenter
public void SetCurrentTime(bool isPostBack) 
{
    if (!isPostBack) 
    {
        view.CurrentTime = DateTime.Now;
    }
}

//Method defined in Presenter
public void AddDays(string daysUnparsed, bool isPageValid) 
{
    if (isPageValid) 
    {
        view.CurrentTime = DateTime.Now.AddDays(double.Parse(daysUnparsed));           
    }
}

using System;
public class MonthPresenter
{
    private IMonthView monthView;

    //Constructor for prsenter
    public MonthPresenter(IMonthView inputView)
    {
        if (inputView == null)
        {
           throw new ArgumentNullException("view may not be null");
        }
        this.monthView = inputView;
    }


    //Method defined in Presenter
    //How does presenter decides the required value.
    public void SetMonth(string monthValueInput) 
    {
       if (!String.IsNullOrEmpty(monthValueInput))
       {
          monthView.MonthName = monthValueInput;
       }
       else
       {

       }        
    }   
}

用户控制

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CurrentTimeView.ascx.cs" Inherits="Views_CurrentTimeView" %>

<asp:Label id="lblMessage" runat="server" /><br />
<asp:Label id="lblCurrentTime" runat="server" /><br />
<br />

<asp:TextBox id="txtNumberOfDays" runat="server" />
<asp:Button id="btnAddDays" Text="Add Days" runat="server" OnClick="btnAddDays_OnClick" ValidationGroup="AddDays" />

using System;
using System.Web.UI;
public partial class Views_CurrentTimeView : UserControl, ICurrentTimeView
{
   //1. User control has no method other than view defined method for attaching presenter
   //2. Properties has only set method

   private CurrentTimePresenter presenter;

   // Delegate 
   public delegate void OnAddDaysClickedDelegate(string strValue);

   // Event 
   public event OnAddDaysClickedDelegate myBtnAddDaysClickedEvent;

   //Provision for getting the presenter in User Control from aspx page.
   public void AttachPresenter(CurrentTimePresenter presenter)
   {
       if (presenter == null)
       {
         throw new ArgumentNullException("presenter may not be null");
       }
       this.presenter = presenter;
   }

   //Implement View s Property
   public DateTime CurrentTime
   {
      set
      {
        //During set of the property, set the control s value
        lblCurrentTime.Text = value.ToString();
      }
   }

   //Event Handler in User Control
   protected void btnAddDays_OnClick(object sender, EventArgs e)
   {
      if (presenter == null)
      {
         throw new FieldAccessException("presenter null");
      }

      //Ask presenter to do its functionality
      presenter.AddDays(txtNumberOfDays.Text, Page.IsValid);

      //Raise event
      if (myBtnAddDaysClickedEvent != null)
      {
        myBtnAddDaysClickedEvent(string.Empty);
      }
   }     
}

用户控制

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MonthViewControl.ascx.cs" Inherits="Views_MonthViewControl" %>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Views_MonthViewControl : System.Web.UI.UserControl, IMonthView
{
   //1. User control has no method other than view defined method for attaching presenter
   //2. Properties has only set method

   private MonthPresenter presenter;

   //Provision for gettng the presenter in User Control from aspx page.
   public void AttachPresenter(MonthPresenter presenter)
   {
      if (presenter == null)
      {
         throw new ArgumentNullException("presenter may not be null");
      }
      this.presenter = presenter;
   }

   //Implement View s Property
   public string MonthName
   {
      set
      {
        //During set of the popert, set the control s value
        lblMonth.Text = value.ToString();
      }
   }

   protected void Page_Load(object sender, EventArgs e)
   {

   }    
}

ASPX 页 次

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowMeTheTime.aspx.cs"      Inherits="ShowTime" %>

<%@ Register TagPrefix="mvpProject" TagName="CurrentTimeView" Src="Views/CurrentTimeView.ascx" %>

<%@ Register TagPrefix="month" TagName="MonthView" Src="Views/MonthViewControl.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>PAGE TITLE </title>
</head>
<body>
<form id="form1" runat="server">

    <mvpProject:CurrentTimeView id="ucCtrlcurrentTimeView" runat="server" 
    />
    <br />
    <br />
    <month:MonthView id="ucCtrlMonthView" runat="server" />

</form>
</body>
</html>

using System;
using System.Web.UI;

public partial class ShowTime : Page
{
    CurrentTimePresenter currentTimePresenter;
    MonthPresenter monthPresenter;

    protected void Page_Load(object sender, EventArgs e) 
    {
       HelperInitCurrentTimeView();
       HelperInitMonth();
    }

    private void HelperInitMonth()
    {
       //Create presenter
       monthPresenter = new MonthPresenter(ucCtrlMonthView);

       //Pass the presenter object to user control
       ucCtrlMonthView.AttachPresenter(monthPresenter);
    }

    private void HelperInitCurrentTimeView() 
    { 
       //Cretes presenter by passing view(user control) to presenter.
       //User control has implemented IView
       currentTimePresenter = new CurrentTimePresenter(ucCtrlcurrentTimeView);

        //Pass the presenter object to user control
        ucCtrlcurrentTimeView.AttachPresenter(currentTimePresenter);

        //Call the presenter action to load time in user control.
        currentTimePresenter.SetCurrentTime(Page.IsPostBack);

        //Event described in User Control ???? Subsribe for it.
        ucCtrlcurrentTimeView.myBtnAddDaysClickedEvent += new Views_CurrentTimeView.OnAddDaysClickedDelegate(CurrentTimeViewControl_AddButtonClicked_MainPageHandler);        
    }

    void CurrentTimeViewControl_AddButtonClicked_MainPageHandler(string strValue)
    {
       string monthValue = "l";
       monthPresenter.SetMonth("SAMPLE VALUE");
       //myGridCntrl.CurentCharacter = theLetterCtrl.SelectedLetter;
       //myGridCntrl.LoadGridValues();
    }
}

职业妇女论坛的一些讨论:

http://forums.asp.net/t/1760921.aspx/1?Model+View+Presenter+Guidelines”rel=“nofollow noreferer”>Model View Presenter - Guidelines

在MVP中,填写证明文件

https://stackoverflow.com/questions/2203906/mvp-should-views-be-able-to-------presenter-methods-directly-or-should-they-alw>MVP - 意见是否应当能够直接使用介绍方法,或者是否总是引起活动?

MVP 页: 1

《多国企业示范——活动

- 介绍人是否使用会议?

为什么讲演者将观光活动而不是在多数协会中采用“传译方法”的观点作为主人。 NET MVP implementations?

Public 观点活动的方法或签名

MVP pattern, how many views to a presenter?

https://stackoverflow.com/questions/429500/mvp-and-user Controls-and-inue> MVP和用户

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

限制对建筑的违反 - asp.net MVP

https://stackoverflow.com/questions/8339303/ Control-modification-in-presentation-layer> 插图层控制改动

Decoupling the view, presentation and ASP.NET Web Forms web-forms

最佳回答

感谢投入。 我提到了MVP快速启动方案Quicks 。 <代码>Model可生成。 我认为,我应该采取这种做法。 欢迎任何想法。

此外,我还张贴了,以收集关于多国企业的一般规则。

选 举

Develop Presenter which can communicate with both View and Model. Presenter may only have knowledge of view interfaces. Even if the concrete view changes, it does not affect presenter.

In the concrete view, control’s event handlers will simply call presenter methods or raise events to which presenter would have subscribed. There should be no presentation rule/logic written in concrete view.

Presenter should have only interface object of model; not concrete model. This is for the ease of Unit Testing

View can refer business entities. However there should no logic written associated with the entity objects. It may just pass the entity object to presenter.

View interface should be an abstraction. It should NOT have any control or System.Web reference. In concrete view, there should be no method other than interface defined methods.

The "Model" never knows about the concrete view as well as the interface view

"Model" can define and raise events. Presenter can subscribe these events raised by model.

Public methods in presenter should be parameterless. View object should access only parameterless methods of presenter. Another option is view can define events to which the presenter can subscribe. Either way, there should be no parameter passing.

Since the model has all the required values (to be stored back in database), there is no need to pass any value to model from view (most of the time). E.g. when an item is selected in dropdown list only the controls’ current index need to be passed to model. Then model knows how to get the corresponding domain values. In this case, the view need not pass anything to presenter. Presenter knows how to get value from view.

View may make use of model directly (without using presenter). E.g. ObjectDataSource s SelectMethod. But controller never knows about the concrete view as well as the interface view.

The presenter references the view interface instead of the view s concrete implementation. This allows you to replace the actual view with a mock view when running unit tests.

问题回答

TLDR 守则。

Here s how I would do it. You say there are 2 controls on the same page. So that can be served by a ContainerVM with references (members) of TimeVM and MonthVM.

  1. TimeVM updates a backing property ResultantDate whenever you do your thing.
  2. ContainerVM has subscribed to property-changed notifications for TimeVM.ResultantDate. Whenever it receives a change notification, it calls MonthVM.SetMonth()

现在可以在不使用任何观点的情况下进行测试,纯粹是在现在一级。

我没有听说过伙伴关系网,但我认为我看着你试图做的事情。

看来,你会与你的主讲人一道罚款,为每个情报和安全局人员做陈述。 在这种情况下,每月和时间。 我认为,这更多的是显示时间。 展期有能力显示月和时间。

• 与多国企业合作。 然后,你需要一份国际日文,该页将予以执行。 (无控制)。 接着,撰写了《展时报》,利用《国际日报》发出和收回价值。

届时,你将实施国际电算器界面。 它将把时间、AddDay事件和月份等物品从该网页的实际控制上转。

So if I understand your writeup. The sequence of event would be something like this.

The user types in the days to add. The user clicks add days Add Days fires the event which calls a method on the Present to add days. The method in the presenter that add days will make it s calculation and other needed steps. The add days method will then use the View pointer in the Presenter to tell the view to update the Month with the calculated value. The View will then take the calculated value set the correct property on the control.

为了进行单位测试,你需要做一个模拟物体,以安装国际电离时间观测器,并用该物体代替实际的页面物体。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签