ASP.NET WebFormsMVP PageDataSource 事件因未知原因执行两次
问题是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想将此作为对您的问题的评论,但要么没有给我这种特权,因为我的徽章数量不足(我可以用 FourSquare 交易吗?),要么用户体验让我太困惑了。这是我的非回答答案:
您发送的trace.axd是否旨在演示问题?在我看来这一切都很正常。它只绑定一位演示者:
根据您问题的 标题,我们预计会看到此事件两次。
但是,标题 和 < 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:
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?
我遇到了同样的问题,快速解决方法是为您的用户控件设置 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.