cachelocation causes "failed to loadviewstate"

Posts   
 
    
bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 12-Sep-2008 03:12:18   

llblgen v2.0 vs 2005

I have a usercontrolA that contains an LlblgenProDatasource2 (lds). The usercontrolA is used within another usercontrolB. When I have lds cachelocation as viewstate, no problem. When I have cachelocation as session, I got the error "Failed to load viewstate. The control tree into which viewstate is being loaded must be..." during postback.

Does any one know why this is the case?

Thanks

BZ

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Sep-2008 04:41:39   

Hi BZ,

Could you please post (or attach is it's too long) the relevant code here (declarative ASPX, relevant code-behind)?

Do you have the full exception message and stack trace?

Are you adding controls dynamically?

David Elizondo | LLBLGen Support Team
bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 12-Sep-2008 08:34:43   

No, I did not add any control dynamically. The code snippets and the error messages are below.

Thanks.

UserControl A = ucBatch_Edit.ascx


<llblgenpro:LLBLGenProDataSource2 ID="ldsBatch" runat="server" MaxNumberOfItemsToReturn="1"
    DataContainerType="EntityCollection" AdapterTypeName="MW.DAL.DatabaseSpecific.DataAccessAdapter, MW.DALDBSpecific"
    EntityFactoryTypeName="MW.DAL.FactoryClasses.BatchEntityFactory, MW.DAL" LivePersistence="False"
    OnPerformSelect="ldsBatch_PerformSelect" OnPerformWork="ldsBatch_PerformWork" CacheLocation="Session" />
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<table border="0" width="100%" id="table20" cellpadding="2" style="border: 1px solid #808080">
    <!--bgcolor="#FFFFFF"-->
    <tr>
        <td class="titlecontent" style="background-image: url('../../../images/title_content_green.gif');
            background-repeat: no-repeat" height="25" colspan="2">
            BATCH INFORMATION</td>
    </tr>
    <tr>
        <td>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:FormView ID="fvBatch" DataKeyNames="Id" runat="server" DataSourceID="ldsBatch"
                        OnItemCommand="fvBatch_ItemCommand" OnItemCreated="fvBatch_ItemCreated" OnItemUpdating="fvBatch_ItemUpdating" OnItemInserting="fvBatch_ItemInserting"
                        Width="100%" DefaultMode="Insert" CellPadding="0" EnableViewState="false" >
                        <InsertItemTemplate>
                        ...
                        </InsertItemTemplate>
                  </asp:FormView>
                </ContentTemplate>
            </asp:UpdatePanel>      
        </td>
    </tr>
</table>

UserControlB = ucBatch_Search


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucBatch_Search.ascx.cs" Inherits="Services_BillReview_uc_ucBatch_Search" %>
<%@ Register Src="ucBatch_Edit.ascx" TagName="ucBatch_Edit" TagPrefix="uc1" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses"
    TagPrefix="llblgenpro" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
...
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
      <uc1:ucBatch_Edit ID="UcBatch_Edit1" runat="server" />
  </ContentTemplate>
</asp:UpdatePanel>
...

The exact error code

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Sep-2008 19:59:55   

Please post the ASPX of the "..." lines (the controls inside). It must be that controls have enableViewstate.

Also, you are using an UpdatePanel inside another UpdatePanel. Could you confirm that this behavior is related to ajax? what if you disable ajax?

David Elizondo | LLBLGen Support Team
bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 13-Sep-2008 22:13:41   

OK, here's the super simplified form page and user control pages. As long as the LLBLGenProDataSource2 in both user controls have EnableViewState=false then I got the error below (if any one of the datasource has EnableViewState=true then the error goes away):

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

User Control A.


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="uc_Dummy1.ascx.cs" Inherits="temp_uc_uc_Dummy1" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses"
    TagPrefix="llblgenpro" %>

<llblgenpro:LLBLGenProDataSource2 ID="ldsBatch" runat="server" MaxNumberOfItemsToReturn="1"
    DataContainerType="EntityCollection" AdapterTypeName="MW.DAL.DatabaseSpecific.DataAccessAdapter, MW.DALDBSpecific"
    EntityFactoryTypeName="MW.DAL.FactoryClasses.BatchEntityFactory, MW.DAL" LivePersistence="False"
    OnPerformSelect="ldsBatch_PerformSelect" OnPerformWork="ldsBatch_PerformWork" CacheLocation="Session" />

User Control B that contains User Control A


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="uc_Dummy.ascx.cs" Inherits="temp_uc_uc_Dummy" %>
<%@ Register Src="uc_Dummy1.ascx" TagName="uc_Dummy1" TagPrefix="uc2" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="llblgenpro" %>
    
<table>
    <tr><td>
        <asp:Button ID="Button1" runat="server" Text="Button" EnableViewState="false"/></td></tr>
    <tr><td><uc2:uc_Dummy1 id="Uc_Dummy1_1" runat="server" /></td></tr>
    <tr><td>
        
        <llblgenpro:LLBLGenProDataSource2 ID="ldsBatches" runat="server" AdapterTypeName="MW.DAL.DatabaseSpecific.DataAccessAdapter, MW.DALDBSpecific"
            DataContainerType="TypedList" TypedListTypeName="MW.DAL.TypedListClasses.BatchSummaryTypedList, MW.DAL" 
            LivePersistence="False" OnPerformSelect="ldsBatches_PerformSelect" OnPerformWork="ldsBatches_PerformWork" 
            CacheLocation="Session" >
        </llblgenpro:LLBLGenProDataSource2></td></tr>
</table>

Form that hosts the user control A


<%@ Page Language="C#" MasterPageFile="~/Navigation/SiteMasterPage.master" AutoEventWireup="true" CodeFile="frm_Dummy.aspx.cs" Inherits="temp_frm_frm_Dummy" Title="Untitled Page" %>

<%@ Register Src="../uc/uc_Dummy.ascx" TagName="uc_Dummy" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ScriptManager id="ScriptManager1" runat="server" EnablePartialRendering="true" />
    &nbsp;<asp:LoginView ID="LoginView1" runat="server">
        <RoleGroups>
            <asp:RoleGroup Roles="Guest">
                <ContentTemplate>
                    You don't have permission to access this function
                </ContentTemplate>
            </asp:RoleGroup>
        </RoleGroups>
        <LoggedInTemplate>
            <!------------ USER CONTROL --------------------->
                <uc1:uc_Dummy ID="Uc_Dummy1" runat="server" />
            <!------------ USER CONTROL --------------------->          
        </LoggedInTemplate>
    </asp:LoginView>
</asp:Content>

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 15-Sep-2008 11:35:26   

I couldn't reproduce it using v.2.5 and VS 2005 (Please try v.2.5).

UC1:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UC1.ascx.cs" Inherits="Test.UC1" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses"
    TagPrefix="llblgenpro" %>
    Start UC1<br /> 
<llblgenpro:llblgenprodatasource2 id="LLBLGenProDataSource2_1" runat="server" adaptertypename="Test.DatabaseSpecific.DataAccessAdapter, TestDBSpecific"
    datacontainertype="EntityCollection" entityfactorytypename="Test.FactoryClasses.CustomersEntityFactory, Test" CacheLocation="Session"></llblgenpro:llblgenprodatasource2>
    End UC1<br />

UC2:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UC2.ascx.cs" Inherits="Test.UC2" %>
<%@ Register Src="UC1.ascx" TagName="UC1" TagPrefix="uc1" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses"
    TagPrefix="llblgenpro" %>
    Start UC2<br /> 
<llblgenpro:llblgenprodatasource2 id="LLBLGenProDataSource2_1" runat="server" adaptertypename="Test.DatabaseSpecific.DataAccessAdapter, TestDBSpecific"
    datacontainertype="EntityCollection" entityfactorytypename="Test.FactoryClasses.OrdersEntityFactory, Test" CacheLocation="Session"></llblgenpro:llblgenprodatasource2>
<uc1:UC1 ID="UC1_1" runat="server" />
    End UC2<br />

Web Form:


<body>
    <form id="form1" runat="server">
    Start form 1<br />
    <asp:ScriptManager id="ScriptManager1" runat="server" EnablePartialRendering="true" />
    <div>
        <asp:LoginView ID="LoginView1" runat="server">
            <LoggedInTemplate>
                This is the LoggedInTemplate<br />      
                <uc1:UC2 ID="UC2_1" runat="server" />
            </LoggedInTemplate>
        </asp:LoginView>    
    </div>
    End form 1<br />
    </form>
</body>

Would you please set teh enableViewState of the LoginView to false? If this doesn't change anything, then please try using v.2.5 of LLBLGen Pro, at leat for the sake of testing?

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 15-Sep-2008 19:44:00   

You are right.

Setting EnableViewState="false" in LoginView does solve the problem.

I wonder why that is the case (the table below summarizes what my findings):

LoginView ViewState datasource1 cached location datasource2 cachedlocation problem

true session session yes true viewstate session no true session viewstate no false either or either or no

Thanks

BZ

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 16-Sep-2008 10:35:55   

Setting EnableViewState="false" in LoginView does solve the problem.

I wonder why that is the case (the table below summarizes what my findings):

I'm not sure but I think ASP.NET messes things up, trying to load the viewstate tree starting at the loginView and looking for view states if child controls.

bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 16-Sep-2008 18:34:17   

So you are saying that in order to have llblgen datasources in my uc1 and uc2 to cache in session I MUST turn off the viewstate in the LoginView control of the parent page?

Isn't this llblgen bug since none of the other aspnet controls have this problem. For instance, when I enable viewstate in the LoginView, in uc1 and uc2 I can enable viewstate of some aspnet controls while disable some other aspnet controls, no problem. With llblgen datasource, yes problem!

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 17-Sep-2008 10:37:37   

Just to confirm my tests, would you please try v.2.5?