PerformGetDbCount firing before Page_Load

Posts   
 
    
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 28-Jun-2011 17:46:29   

2.6.10.809 (SD.LLBLGen.Pro.LinqSupportClasses.NET35.dll) 2.6.10.930 (SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll) 2.6.10.917 (SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll)

I am having trouble using the paging on the datasource with events. I use the MVP pattern, so code behind just fires another handler for the presenter to listen to and run real code.

It looks like on moving from one page to another, the PerformGetDbCount and PerformSelect events fire after the Page_Init but before the Page_Load of the user control they are on. This means the attaching of listeners to events happens after the datasource events have fired. This only happens when paging. Other PostBacks run the Page_Load first.

So is this what is meant to happen when paging?

Page_Init -> PerformGetDbCount -> PerformSelect -> Page_Load

If not, how have I screwed it up to work like this?

Here is the datasource:

<llblgenpro:LLBLGenProDataSource2 ID="RegulationListDataSource" runat="server" CacheLocation="Session"
    AdapterTypeName="MyCompany.BusinessObjects.Adapter.DatabaseSpecific.DataAccessAdapter, MyCompany.BusinessObjects.Adapter"
    DataContainerType="EntityCollection" EntityFactoryTypeName="MyCompany.BusinessObjects.Adapter.FactoryClasses.RegulationTextEntityFactory, MyCompany.BusinessObjects.Adapter"
    LivePersistence="false" OnPerformSelect="RegulationListDataSource_PerformSelect"
    OnPerformWork="RegulationListDataSource_PerformWork" EnablePaging="true" 
    OnPerformGetDbCount="RegulationListDataSource_PerformGetDbCount" 
    AllowDuplicates="False">
</llblgenpro:LLBLGenProDataSource2>

Here is the code behind handler

        protected void RegulationListDataSource_PerformGetDbCount(object sender, PerformGetDbCountEventArgs2 e)
        {
            var handler = RegulationListDataSourcePerformGetDbCount;
            if (handler != null) handler(sender, e);
        }

Here is the Page_Load method:

        protected void Page_Load(object sender, EventArgs e)
        {
            var presenter = new Presenter(this);
            presenter.InitView(IsPostBack);
         }

The InitView() method does the listening and sets up variables to use in the Model to create data and get the count. As long as Page_Load runs, it all works fine.

Am I doing something wrong or do I need to set something else up somewhere?

Note that if I move all database accessing to the code-behind, then it works. This isn't our coding style though, so I am keen to sort it out so it will work with the MVP pattern.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Jun-2011 21:44:51   

Your setup looks OK to me. Could you do the initialisation in the Page_Init event, rather than in the Page_load...?

Matt

neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 28-Jun-2011 23:33:12   

MTrinder wrote:

Your setup looks OK to me. Could you do the initialisation in the Page_Init event, rather than in the Page_load...?

Matt

Maybe. I'll try it. I would prefer to find out what I could be doing wrong though.

I have written a test from scratch with none of the fancy ui around and inside the grid and only allowed one datasource on the .ascx page. There were 3 before powering several other databound controls.

The test works perfectly. That means there is something in my code that is causing the problem.

The controls are a combination of DevExpress and vanilla ASP.NET, with the ASPxGridView being paged and working just fine on page 1.

All I can do is eliminate stuff piece by piece until I find the cause. Any possible areas to look would be gratefully received. At the moment I am perplexed as debugging shows exactly what I said in the original post. A threading issue caused by multiple controls and datasources maybe?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jun-2011 04:44:28   

neilx wrote:

All I can do is eliminate stuff piece by piece until I find the cause. Any possible areas to look would be gratefully received. At the moment I am perplexed as debugging shows exactly what I said in the original post. A threading issue caused by multiple controls and datasources maybe?

I would go for debugging and place control event listeners to see what is triggering what. Remove/Add the control could fix this as you don't really know where this is happening.

David Elizondo | LLBLGen Support Team
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 29-Jun-2011 07:56:55   

daelmo wrote:

neilx wrote:

All I can do is eliminate stuff piece by piece until I find the cause. Any possible areas to look would be gratefully received. At the moment I am perplexed as debugging shows exactly what I said in the original post. A threading issue caused by multiple controls and datasources maybe?

I would go for debugging and place control event listeners to see what is triggering what. Remove/Add the control could fix this as you don't really know where this is happening.

Do you mean adding all possible event handlers to all the controls and stepping through?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Jun-2011 09:52:16   

It looks like on moving from one page to another, the PerformGetDbCount and PerformSelect events fire after the Page_Init but before the Page_Load of the user control they are on. This means the attaching of listeners to events happens after the datasource events have fired.

AFAIK, conrols are loaded first befoe Page_Load. DataSourrces would be loaded and then PerformGetDbCount and PerformSelect would be called first. You'd either attach listeners in the Page_Init, or manually bind controls to datasources in the Page_Load.

neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 29-Jun-2011 16:32:16   

Well no. The normal operation first time through and on PostBack is:

Page_Init->Page_Load -> GetDbCount -> PerformSelect.

It turns out the the developer who wrote the original code had a problem that they fixed by setting EnableRowsCache="false" on the ASPxGridView. This is what screws up things when an Eval is used in a DataItemTemplate. I set it to true and now the events are fired correctly. I have no idea why this problem occurs though.

(I still have to solve the original developer's problem, but that's a different story.)

Thanks for your responses!