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" />
<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.