ASP.NET WebFormsMVP PageDataSource Events Executing Twice For Unknown Reason

691 views Asked by At

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.

2

There are 2 answers

0
Mark Dowell On

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.

1
Tatham Oddie On

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?