Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用MVP-如何正确使用事件进行测试_Asp.net_Design Patterns_Mvp - Fatal编程技术网

Asp.net 使用MVP-如何正确使用事件进行测试

Asp.net 使用MVP-如何正确使用事件进行测试,asp.net,design-patterns,mvp,Asp.net,Design Patterns,Mvp,我刚刚开始在我正在构建的大型ASP.NET应用程序中使用MVP模式(实际上是重新构建),我很难弄清楚应该如何使用应用于视图的事件 假设在用户控件中有两个下拉列表,其中一个取决于另一个的值: <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ucTestMVP.ascx.vb" Inherits=".ucTestMVP" %> <asp:DropDownList ID="ddlCountry" ru

我刚刚开始在我正在构建的大型ASP.NET应用程序中使用MVP模式(实际上是重新构建),我很难弄清楚应该如何使用应用于视图的事件

假设在用户控件中有两个下拉列表,其中一个取决于另一个的值:

<%@ 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" />

或者应该在接口上定义一个事件?如果这是首选模式,如何添加要处理和使用的事件?

我不知道是否有普遍首选的模式。我倾向于将事件添加到视图界面,并让演示者响应视图。我在一篇文章中描述了这种模式

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