ASP.NET WebFormsMVP PageDataSource 事件因未知原因执行两次

发布于 2024-09-24 09:53:17 字数 773 浏览 7 评论 0原文

问题是 SelectMethod 和其他操作执行两次。这很难隔离,因为它只发生在较大的解决方案中,而不是在更简单的演示应用程序中。

//.ascx
<asp:FormView runat="server" DataSourceID="userSource" DefaultMode="Edit">
    <EditItemTemplate>

<mvp:PageDataSource id="userSource" SelectMethod="GetUser" />

//code behind 
public User GetUser()
{
     //returning single item as FormView is only DefaultMode=edit
     return Model.User;
}

//presenter
public class UserOtherEditPresenter<IUserOtherEditView<UserEditViewModel>>

尝试在此处调试此跟踪 AXD 文件

更新:

正如已经指出的那样,初始化似乎没问题,因此问题一定出在与应用程序的其他方面发生冲突的其他地方。

The problem is SelectMethod and other actions execute twice. This has been difficult to isolate, as it only occurs on a larger solution, and not in simpler demo applications.

//.ascx
<asp:FormView runat="server" DataSourceID="userSource" DefaultMode="Edit">
    <EditItemTemplate>

<mvp:PageDataSource id="userSource" SelectMethod="GetUser" />

//code behind 
public User GetUser()
{
     //returning single item as FormView is only DefaultMode=edit
     return Model.User;
}

//presenter
public class UserOtherEditPresenter<IUserOtherEditView<UserEditViewModel>>

In an attempt to debug this here is the trace AXD file.

Update:

As it has been pointed out that initialization seems fine, so the problem must lie elsewhere in a conflict with some other aspect of the application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谷夏 2024-10-01 09:53:17

我想将此作为对您的问题的评论,但要么没有给我这种特权,因为我的徽章数量不足(我可以用 FourSquare 交易吗?),要么用户体验让我太困惑了。这是我的非回答答案:

您发送的trace.axd是否旨在演示问题?在我看来这一切都很正常。它只绑定一位演示者:

正在为 ADC.Logic.Views.IUserOtherEditView`1 类型的视图创建 ADC.Logic.Presenters.UserOtherEditPresenter 类型的演示者[[ADC.Logic.Views.Models.UserEditViewModel, ADC.Logic, Version=1.0.0.0, Culture] =中性,PublicKeyToken = null]]。 (实际视图实例的类型为 ASP.controls_userotheredit_ascx。

根据您问题的 标题,我们预计会看到此事件两次。

但是,标题 和 < em>您的问题的内容与我不匹配,您是说 SelectMethod 被多次触发,这可能表明 PageDataSource 有问题,

您能澄清一下吗?

I wanted to post this as a comment on your question but SO either isn't giving me that privilege because I have an insufficient number of badges (can I trade in FourSquare ones?), or the UX is just confusing me too much. Here's my non-answer answer:

Is the trace.axd you sent meant to demonstrate the problem? It all looks normal to me. It's only binding one presenter:

Creating presenter of type ADC.Logic.Presenters.UserOtherEditPresenter for view of type ADC.Logic.Views.IUserOtherEditView`1[[ADC.Logic.Views.Models.UserEditViewModel, ADC.Logic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. (The actual view instance is of type ASP.controls_userotheredit_ascx.

According to the title of your question we'd expect to see this event twice.

However, the title and the content of your question don't match for me. You're saying the SelectMethod gets fired multiple times, which could indicate a problem with the PageDataSource.

Can you clarify please?

两人的回忆 2024-10-01 09:53:17

我遇到了同样的问题,快速解决方法是为您的用户控件设置 AutoDataBind = false 。这将停止对 FormView 的 DataBind 的第二次调用,进而停止对 SelectMethod 的第二次调用。
对 formView.DataBind 的第一次调用作为 Page.ProcessRequestMain 的一部分发生,并且由于数据网格上的 DataSourceID 而发生。

I had the same problem, the quick fix is to set AutoDataBind = false for your user control. This stops the second call to DataBind of the FormView which in turn stops the second call to the SelectMethod.
The first call to formView.DataBind happens as part of Page.ProcessRequestMain and happens due to the DataSourceID on the datagrid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文