LLBLGenProDataSource2 and ASP.NET 2.0 DataList

Posts   
 
    
Posts: 6
Joined: 07-Sep-2006
# Posted on: 06-Oct-2006 23:11:49   

I am using LLBLGen Pro v2.0. The SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version is 2.0.0.060921.

I'm having an issue with the LLBLGenProDataSource2 control and an ASP.NET 2.0 DataList control.

I'm using the data source control with LivePersistence set to false and EnableViewState set to false. When the page loads initially everything works as I would expect with the PerformSelect event firing after all the page/user control load events. But when a post back happens after clicking a button in the browser the PerformSelect event occurs before any load/click events happen.

I tried to figure out what might be causing this, and I narrowed it down. If the DataList ItemTemplate contains a TextBox control then the PerformSelect event fires before I would expect. If I take out the TextBox control and leave just Label controls then the PerformSelect fires after the page load event.

I created a scaled down example of the code that is having the problem.

The ASP.NET page source:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestEvents.aspx.vb" Inherits="TestEvents" %>
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <asp:DataList ID="DataList1" runat="server" DataSourceID="ds2" EnableViewState="False">
          <ItemTemplate>
             WarnIfNoModel:
             <asp:Label ID="WarnIfNoModelLabel" runat="server" Text='<%# Eval("WarnIfNoModel") %>'>
             </asp:Label><br />
             <asp:TextBox ID="txt1" runat="server" />
             <br />
          </ItemTemplate>
       </asp:DataList>
       <llblgenpro:LLBLGenProDataSource2 ID="ds2" runat="server" DataContainerType="TypedView"
          EnableViewState="False" LivePersistence="False" TypedViewTypeName="Lib.Entities.TypedViewClasses.PartSearchResultsTypedView, Lib.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ce571910e9bd08c9">
       </llblgenpro:LLBLGenProDataSource2>
       <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

The code behind:


Imports Lib.Controllers

Partial Class TestEvents
    Inherits System.Web.UI.Page

   Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

   End Sub

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

   End Sub

   Protected Sub ds2_PerformSelect(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2) Handles ds2.PerformSelect
      ds2.TypedView = New SearchController().GetSearchResults(29)
   End Sub
End Class

With the TextBox control in the DataList the ds2_PerformSelect is fired before Page_Load and Button1_Click. If you take out the TextBox control then the ds2_PerformSelect fires after Page_Load and Button1_Click. This causes a problem in the actual code because I am initializing some values in the Load events that is needed by the PerformSelect event.

I am getting around this problem by ignoring the initial PerformSelect if Page_Load hasn't occurred, then call Select on the data source after processing the click event. The problem is I'm not sure if this might cause other issues that I haven't found yet.

I certainly could be doing something wrong, but it seems like a possible bug with either LLBLGen or probably more likly Microsoft or me wink

If I need to provide any more information, please let me know.

Thank you!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39922
Joined: 17-Aug-2003
# Posted on: 07-Oct-2006 11:12:59   

When a page is build and rendered (thus after a postback) the controls are instantiated and a bound control like a grid or datalist asks its datasourcecontrol for the data. it always does that.

The datasourcecontrol then gives back the data it needs. If there's nothing changed, the data cached from the previous fetch is returned. If something changed, like a select parameter changed, etc., the data is fetched again.

On september 22nd, a bug was fixed in the datasourcecontrols which fixed an issue very similar to this one, which made the datasourcecontrol fetch the data everytime a select parameter was changed. I'm not sure if this also fixes your problem, but internally in the code some things were rescheduled so it might fix this issue as well.

Anyway, the data shouldn't be refetched in the postback.

Could you try the latest runtimes (and also make sure your webapp indeed uses the latest ones, vs.net not always refreshes assemblies in webapps)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 6
Joined: 07-Sep-2006
# Posted on: 07-Oct-2006 22:18:08   

I upgraded to SD.LLBLGen.Pro.ORMSupportClasses.NET20.DLL version 2.0.0.061005. The PerformSelect still fires before the page load events on postback. I double checked the loaded assembly under the debugger to make sure ASP.NET was using the correct version.

We prefer on post back to refetch the data from the database. Viewstate becomes to large for our desired page size and we don't use ASP.NET session. We rolled our own session persistence mechanism for some user session settings, but we do not put cached control data in session. If we were to add the data source cached data for the DataList to our session it would end up going in the database anyway. We run on load balanced web servers with no affinity set, so session can not be cached locally on the web server.

I think maybe we are not using the control in the standard way, so maybe this is really the issue. I think caching is the expected way to use ASP.NET.

My work around seems to do the trick. I can see over time if there are any other issues.

Thanks for taking the time to help out!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Oct-2006 09:11:52   

A good reference..."ASP.NET Page Life Cycle Overview": http://msdn2.microsoft.com/en-us/library/ms178472.aspx