- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
LivePersistence is not working for me
Joined: 13-Jan-2006
I can't seem to get my formview to update my db automatically using LivePersistence set to True. I turned on tracing (level 4) for SqlServerDQE, ORMGeneral, ORMStateManagement and ORMPersistenceExecution and get NO messages from the point when I click the OK button on my form (it is in Edit mode).
I DO get the FormViewInsertEvent (I have a handler for it where I modify the entered data slightly before it is persisted to the db).
I set up things using a mix of declarative code and runtime stuff - maybe I'm doing something wrong there. Also, I have master pages and subclass UI.Pages in the mix
.net 2.0 designer = v 2.0.0.0 mar 19, 2007 sql server 2005 ORMSupportClasses dll version = 2.0.7.319 DQESQLServer dll version = 2.0.7.129
I'm including 4 snippets of code. The first is the mastpage that my edit forms use, the second is the page (homepage.aspx) that I've been trying to get to work, the third is an ascx that is called up by homepage.aspx (so that I don't have to duplicate markup between the Insert and Update FormView templates), and finally the fourth in the PageLoad method for the homepage.aspx file.
*** 1 Here's the form's Master Page:
<head runat="server">
<link href="~/DefaultAdmin.css" media="screen, print" rel="stylesheet" type="text/css" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc2:layout1 id="Layout1_1" runat="server" />
<llblgenpro:LLBLGenProDataSource2
ID="LLBLGenProDataSource2_1"
CacheLocation="Session"
LivePersistence="true"
AdapterTypeName="Standards.DatabaseSpecific.DataAccessAdapter, StandardsDBSpecific"
runat="server">
</llblgenpro:LLBLGenProDataSource2>
<asp:FormView ID="FormView1" DataSourceID="LLBLGenProDataSource2_1" DefaultMode="Edit" runat="server">
<InsertItemTemplate>
<asp:contentplaceholder id="ContentPlaceHolder_AddControls" runat="server">
</asp:contentplaceholder>
<asp:Button ID="Button_OK" runat="server" Text="OK" CommandName="Insert" />
<asp:Button ID="Button_Cancel" runat="server" Text="Cancel" UseSubmitBehavior="false" OnClick="Button_Cancel_Click" />
</InsertItemTemplate>
<EditItemTemplate>
<asp:contentplaceholder id="ContentPlaceHolder_EditControls" runat="server">
</asp:contentplaceholder>
<asp:Button ID="Button_OK" runat="server" Text="OK" CommandName="Update" />
<asp:Button ID="Button_Cancel" runat="server" Text="Cancel" UseSubmitBehavior="false" OnClick="Button_Cancel_Click" />
</EditItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
**** 2 The content placeholder contents:
<asp:Content ID="Content_Add" ContentPlaceHolderID="ContentPlaceHolder_AddControls" Runat="Server">
<uc1:homepage_template id="Homepage_template_Insert" runat="server">
</uc1:homepage_template>
</asp:Content>
<asp:Content ID="Content_Edit" ContentPlaceHolderID="ContentPlaceHolder_EditControls" Runat="Server">
<uc1:homepage_template id="Homepage_template_Edit" runat="server">
</uc1:homepage_template>
</asp:Content>
**** 3 the ascx files referenced in **** 2, above:
<div id="header">
<div id="subheader1">
<div id="subheader1_left" style="width:310px;float:left;">
<div style="float:left;">
<asp:Label ID="Label_OrganizationEn" runat="server" Text="Organization Name (En)"></asp:Label>
</div>
<div style="float:right;">
<radI:RadTextBox ID="RadTextBox_OrganizationEn" Text='<%# Bind("NameE") %>' runat="server" />
</div>
</div>
<div id="subheader1_right" style="width:310px;float:left;">
<asp:Label ID="Label_OrganizationFr" runat="server" Text="Organization Name (Fr)"></asp:Label>
<radI:RadTextBox ID="RadTextBox_OrganizationFr" Width="100%" Text='<%# Bind("NameF") %>' runat="server">
</radI:RadTextBox>
</div>
<extRadTS:RadTabStripExtended
id="RadTabstrip_TabbedControls"
MultiPageID="RadMultiPage_TabbedControls"
SelectedIndex="0"
runat="server"
AutoPostBack="true"
OnTabClick="RadTabstrip_TabbedControls_TabClick">
<Tabs>
<radTS:Tab runat="server" Text="About Us"></radTS:Tab>
<radTS:Tab runat="server" Text="Activities"></radTS:Tab>
<radTS:Tab runat="server" Text="Working Groups"></radTS:Tab>
<radTS:Tab runat="server" Text="Documents"></radTS:Tab>
<radTS:Tab runat="server" Text="Bottom"></radTS:Tab>
</Tabs>
</extRadTS:RadTabStripExtended>
<radTS:RadMultiPage ID="RadMultiPage_TabbedControls" SelectedIndex="0" runat="server">
<radTS:PageView ID="PageView_AboutUs" Visible="true" runat="server">
<uc1:homepage_aboutus
ID="Homepage_aboutus1"
runat="server"
EntityFieldNameEn="AboutUsE"
EntityFieldNameFr="AboutUsF" />
</radTS:PageView>
<radTS:PageView ID="PageView_Activities" Visible="false" runat="server">
<uc2:homepage_allother
ID="Homepage_allother_Activities"
runat="server"
EntityFieldNameEn="ActivitiesTextE"
EntityFieldNameFr="ActivitiesTextF"
EntityFieldNameIncludeSection="IncludeActivities"
EntityFieldNameHeadingEn="ActivitiesHeadingE"
EntityFieldNameHeadingFr="ActivitiesHeadingF" />
</radTS:PageView>
<radTS:PageView ID="PageView_WorkingGroups" Visible="false" runat="server">
<uc2:homepage_allother
ID="Homepage_allother_WorkingGroups"
runat="server"
EntityFieldNameEn="GroupTextE"
EntityFieldNameFr="GroupTextF"
EntityFieldNameIncludeSection="IncludeGroups"
EntityFieldNameHeadingEn="GroupsHeadingE"
EntityFieldNameHeadingFr="GroupsHeadingF" />
</radTS:PageView>
<radTS:PageView ID="PageView_Documents" Visible="false" runat="server">
<uc2:homepage_allother
ID="Homepage_allother_Documents"
runat="server"
EntityFieldNameEn="DocumentsE"
EntityFieldNameFr="DocumentsF"
EntityFieldNameIncludeSection="IncludeDraftsIssues"
EntityFieldNameHeadingEn="DraftsIssuesHeadingE"
EntityFieldNameHeadingFr="DraftsIssuesHeadingF" />
</radTS:PageView>
<radTS:PageView ID="PageViewBottom" Visible="false" runat="server">
<uc2:homepage_allother
ID="Homepage_allother_Bottom"
runat="server"
EntityFieldNameEn="BottomE"
EntityFieldNameFr="BottomF"
EntityFieldNameIncludeSection="IncludeBottom"
EntityFieldNameHeadingEn="BottomHeadingE"
EntityFieldNameHeadingFr="BottomHeadingF" />
</radTS:PageView>
</radTS:RadMultiPage>
</div>
</div>
*** 4 Here's the PageLoad for a page that uses the above master page:
protected void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
if (!IsPostBack)
{
LLBLGenProDataSource2 dataSource = (LLBLGenProDataSource2)FindControlRecursive.FindControl(Page, "LLBLGenProDataSource2_1");
dataSource.DataContainerType = DataSourceDataContainerType.EntityCollection;
dataSource.EntityFactoryTypeName = "Standards.FactoryClasses.OrganizationEntityFactory, Standards";
FormView formView = (FormView)FindControlRecursive.FindControl(Page, "FormView1");
if (EntityId != 0)
{
formView.ChangeMode(FormViewMode.Edit);
RelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add((OrganizationFields.Id == EntityId));
dataSource.FilterToUse = filter;
}
else
{
formView.ChangeMode(FormViewMode.Insert);
}
}
}
Joined: 16-Nov-2006
i'm not 100% sure however I would certainly suggest declaring the DataKeyNames attribute on the FormView class. This should be set to the unique identifier of the entity being edited in the form view e.g. OrganisationId
Joined: 13-Jan-2006
I would certainly suggest declaring the DataKeyNames attribute on the FormView class
I tried that (I added the code below to the page's Page_Load() but it hasn't changed anything.
String[] keys = {"Id"};
formView.DataKeyNames = keys;
Joined: 21-Aug-2005
The UpdateParameters are used to set default values (not taken from user inputs).
I'd suggest you set the DataKeyName directly in the asp:FormView tag, especially if all the entities using this MasterPage FormView have an Id column for the PK.
Does the Insert work?
Joined: 13-Jan-2006
I simplified the code to try to solve this problem and have removed all event handlers.
I did ADD a new event handler just now to try to diagnose the problem - ItemUpdating event handler. I just put a no-op in it that I could break on.
The FormViewItemUpdateEventArgs parameter has an OldValues and NewValues fields which I assume is a collection of the old/new bound field/value pairs. Well, the count of both collections is 0. I think this is wrong but don't know why it isn't working especially since the Update form template does successfully show the field values in the various controls.
Here's the new, simpler code that still doesn't work
The master.page:
<form id="form1" runat="server">
<div>
<uc2:layout1 id="Layout1_1" runat="server" />
<uc1:MainTabs ID="MainTabs1" runat="server" />
<llblgenpro:LLBLGenProDataSource2
ID="LLBLGenProDataSource2_1"
CacheLocation="Session"
LivePersistence="true"
AdapterTypeName="Standards.DatabaseSpecific.DataAccessAdapter, StandardsDBSpecific"
runat="server">
</llblgenpro:LLBLGenProDataSource2>
<asp:FormView
ID="FormView1"
DataSourceID="LLBLGenProDataSource2_1"
DataKeyNames="Id"
DefaultMode="ReadOnly"
runat="server">
<ItemTemplate>
<div class="ReadControlsWrapper">
<asp:contentplaceholder id="ContentPlaceHolder_ReadControls" runat="server">
</asp:contentplaceholder>
</div>
</ItemTemplate>
<InsertItemTemplate>
<div class="AddControlsWrapper">
<asp:contentplaceholder id="ContentPlaceHolder_AddControls" runat="server">
</asp:contentplaceholder>
<div class="AddEditOKCancel">
<div class="AddEditOK">
<asp:Button ID="Button_OK" CssClass="FloatRight" runat="server" Text="OK" CommandName="Insert" />
</div>
<div class="AddEditCancel">
<asp:Button ID="Button_Cancel" CssClass="FloatLeft" runat="server" Text="Cancel" UseSubmitBehavior="false" OnClick="Button_Cancel_Click" />
</div>
</div>
</div>
</InsertItemTemplate>
<EditItemTemplate>
<div class="EditControlsWrapper">
<asp:contentplaceholder id="ContentPlaceHolder_EditControls" runat="server">
</asp:contentplaceholder>
<div class="AddEditOKCancel">
<div class="AddEditOK">
<asp:Button ID="Button_OK" CssClass="FloatRight" runat="server" Text="OK" CommandName="Update" />
</div>
<div class="AddEditCancel">
<asp:Button ID="Button_Cancel" CssClass="FloatLeft" runat="server" Text="Cancel" UseSubmitBehavior="false" OnClick="Button_Cancel_Click" />
</div>
</div>
</div>
</EditItemTemplate>
</asp:FormView>
</div>
</form>
The Update template from homepage.aspx (which uses the master page):
<div class="SubHeader">
<div class="SubHeaderLeft">
<div class="LabelAndTextBox FloatLeft">
<div class="LabelPart FloatLeft">
<asp:Label
ID="Label_OrganizationEn"
runat="server"
Text="Organization Name (En)" />
</div>
<div class="TextBoxPart FloatRight">
<radI:RadTextBox
ID="RadTextBox_OrganizationEn"
Width="100%"
Text='<%# Bind("NameE") %>'
runat="server" />
</div>
</div>
</div>
...etc
LoadPage code from homepage.aspx:
if (!IsPostBack)
{
// Set the NavigateUrl for the Preview based on the currently selected language
// radiobutton on this page and the SPO website app setting in web.config ("WebSiteURI").
// Also uses an AppSetting for the SPO's organization Id ("SPOOrgId").
LLBLGenProDataSource2 dataSource = (LLBLGenProDataSource2)FindControlRecursive.FindControl(Page, "LLBLGenProDataSource2_1");
dataSource.DataContainerType = DataSourceDataContainerType.EntityCollection;
dataSource.EntityFactoryTypeName = "Standards.FactoryClasses.OrganizationEntityFactory, Standards";
RelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add((OrganizationFields.Id == Int32.Parse(ConfigurationManager.AppSettings["SPOOrgId"])));
dataSource.FilterToUse = filter;
FormView formView = (FormView)FindControlRecursive.FindControl(Page, "FormView1");
// String[] dataKeys = {"Id"};
// formView.DataKeyNames = dataKeys;
}
}
Joined: 13-Jan-2006
I'm really stumped too. I suspect it has something to do with fact that I am doing a mixture of declarative setting and attributes and programmatic setting of properties.
I set LivePersistence to 'false' and added event handlers for the PerformSelect and PerformWork. And, yes, I can intercept the PerformSelect event.
I don't get a PerformWork event but that's most probably because I don't do the required selection of a record in the PerformSelect (how do I do that? I don't see anything in the llblgen user manual). As a result of not selecting a record, my formview's readonly template displays nothing because the record count is 0.
I'm going to try hard coding everything declaratively (in aspx and master page) to see if that works as an experiment. This won't be a proper solution though in the end - I need to get my current design working to do this app.
Joined: 13-Jan-2006
I hardcoded everything in aspx and master page and turned on diagnostics. Here is the output from the point when I click on the button associated with the Update command. I've bolded a line that shows that the llblgen library can't find anything to save (must be because the FormView's OldValue/NewValue collections are empty):
- A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
- Method Enter: DataAccessAdapterBase.SaveEntity(4)
- Active Entity Description:
- Entity: Standards.EntityClasses.OrganizationEntity. ObjectID: 1e5468ec-03f4-4d02-8dc7-a889500e98cf
- PrimaryKey field: Id. Type: System.Int32. Value: 4
- Method Enter: DataAccessAdapterBase.DetermineActionQueues(7)
- Active Entity Description:
- Entity: Standards.EntityClasses.OrganizationEntity. ObjectID: 1e5468ec-03f4-4d02-8dc7-a889500e98cf
- PrimaryKey field: Id. Type: System.Int32. Value: 4
- Method Exit: DataAccessAdapterBase.DetermineActionQueues(7)
- Method Exit: DataAccessAdapterBase.SaveEntity(4): no entities to save.
- Method Enter: CollectionCore.Clear
- Method Exit: CollectionCore.Clear
- Method Enter: DataAccessAdapterBase.OpenConnection
- New connection created.
-
Connection physically opened. Method Exit: DataAccessAdapterBase.OpenConnection Method Enter: DataAccessAdapterBase.FetchEntityCollection(7) Method Enter: DataAccessAdapterBase.FetchEntityCollection(5) Method Enter: DataAccessAdapterBase.FetchEntityCollectionInternal(6) Active Entity Collection Description: EntityCollection: SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionNonGeneric. Will contain entities of type: OrganizationEntity
Method Enter: CreatePagingSelectDQ Method Enter: CreateSelectDQ Method Enter: CreateSelectDQ Generated Sql query: Query: SELECT [Standards].[dbo].[Organization].[ID] AS [Id], [Standards].[dbo].[Organization].[Name_e] AS [NameE], [Standards].[dbo].[Organization].[Name_f] AS [NameF], [Standards].[dbo].[Organization].[Parent_ID] AS [ParentId], [Standards].[dbo].[Organization].[Tree_Level] AS [TreeLevel], [Standards].[dbo].[Organization].[PreOrder], [Standards].[dbo].[Organization].[PostOrder], [Standards].[dbo].[Organization].[About_Heading_e] AS [AboutHeadingE], [Standards].[dbo].[Organization].[About_Heading_f] AS [AboutHeadingF], [Standards].[dbo].[Organization].[About_Us_e] AS [AboutUsE], [Standards].[dbo].[Organization].[About_Us_f] AS [AboutUsF], [Standards].[dbo].[Organization].[Include_Activities] AS [IncludeActivities], [Standards].[dbo].[Organization].[Activities_Heading_e] AS [ActivitiesHeadingE], [Standards].[dbo].[Organization].[Activities_Heading_f] AS [ActivitiesHeadingF], [Standards].[dbo].[Organization].[Activities_Text_e] AS [ActivitiesTextE], [Standards].[dbo].[Organization].[Activities_Text_f] AS [ActivitiesTextF], [Standards].[dbo].[Organization].[Include_Groups] AS [IncludeGroups], [Standards].[dbo].[Organization].[Groups_Heading_e] AS [GroupsHeadingE], [Standards].[dbo].[Organization].[Groups_Heading_f] AS [GroupsHeadingF], [Standards].[dbo].[Organization].[Group_Text_e] AS [GroupTextE], [Standards].[dbo].[Organization].[Group_Text_f] AS [GroupTextF], [Standards].[dbo].[Organization].[Include_Drafts_Issues] AS [IncludeDraftsIssues], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_e] AS [DraftsIssuesHeadingE], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_f] AS [DraftsIssuesHeadingF], [Standards].[dbo].[Organization].[Documents_e] AS [DocumentsE], [Standards].[dbo].[Organization].[Documents_f] AS [DocumentsF], [Standards].[dbo].[Organization].[Include_Bottom] AS [IncludeBottom], [Standards].[dbo].[Organization].[Bottom_Heading_e] AS [BottomHeadingE], [Standards].[dbo].[Organization].[Bottom_Heading_f] AS [BottomHeadingF], [Standards].[dbo].[Organization].[Bottom_e] AS [BottomE], [Standards].[dbo].[Organization].[Bottom_f] AS [BottomF], [Standards].[dbo].[Organization].[Date_Created] AS [DateCreated], [Standards].[dbo].[Organization].[Date_Published] AS [DatePublished], [Standards].[dbo].[Organization].[Last_Updated] AS [LastUpdated], [Standards].[dbo].[Organization].[Date_Reviewed] AS [DateReviewed] FROM [Standards].[dbo].[Organization] WHERE ( ( ( [Standards].[dbo].[Organization].[ID] = @Id1))) Parameter: @Id1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 4.
Method Exit: CreateSelectDQ Method Exit: CreatePagingSelectDQ: no paging. Method Enter: DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery Method Enter: DataAccessAdapterBase.OpenConnection Method Exit: DataAccessAdapterBase.OpenConnection Executed Sql Query: Query: SELECT [Standards].[dbo].[Organization].[ID] AS [Id], [Standards].[dbo].[Organization].[Name_e] AS [NameE], [Standards].[dbo].[Organization].[Name_f] AS [NameF], [Standards].[dbo].[Organization].[Parent_ID] AS [ParentId], [Standards].[dbo].[Organization].[Tree_Level] AS [TreeLevel], [Standards].[dbo].[Organization].[PreOrder], [Standards].[dbo].[Organization].[PostOrder], [Standards].[dbo].[Organization].[About_Heading_e] AS [AboutHeadingE], [Standards].[dbo].[Organization].[About_Heading_f] AS [AboutHeadingF], [Standards].[dbo].[Organization].[About_Us_e] AS [AboutUsE], [Standards].[dbo].[Organization].[About_Us_f] AS [AboutUsF], [Standards].[dbo].[Organization].[Include_Activities] AS [IncludeActivities], [Standards].[dbo].[Organization].[Activities_Heading_e] AS [ActivitiesHeadingE], [Standards].[dbo].[Organization].[Activities_Heading_f] AS [ActivitiesHeadingF], [Standards].[dbo].[Organization].[Activities_Text_e] AS [ActivitiesTextE], [Standards].[dbo].[Organization].[Activities_Text_f] AS [ActivitiesTextF], [Standards].[dbo].[Organization].[Include_Groups] AS [IncludeGroups], [Standards].[dbo].[Organization].[Groups_Heading_e] AS [GroupsHeadingE], [Standards].[dbo].[Organization].[Groups_Heading_f] AS [GroupsHeadingF], [Standards].[dbo].[Organization].[Group_Text_e] AS [GroupTextE], [Standards].[dbo].[Organization].[Group_Text_f] AS [GroupTextF], [Standards].[dbo].[Organization].[Include_Drafts_Issues] AS [IncludeDraftsIssues], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_e] AS [DraftsIssuesHeadingE], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_f] AS [DraftsIssuesHeadingF], [Standards].[dbo].[Organization].[Documents_e] AS [DocumentsE], [Standards].[dbo].[Organization].[Documents_f] AS [DocumentsF], [Standards].[dbo].[Organization].[Include_Bottom] AS [IncludeBottom], [Standards].[dbo].[Organization].[Bottom_Heading_e] AS [BottomHeadingE], [Standards].[dbo].[Organization].[Bottom_Heading_f] AS [BottomHeadingF], [Standards].[dbo].[Organization].[Bottom_e] AS [BottomE], [Standards].[dbo].[Organization].[Bottom_f] AS [BottomF], [Standards].[dbo].[Organization].[Date_Created] AS [DateCreated], [Standards].[dbo].[Organization].[Date_Published] AS [DatePublished], [Standards].[dbo].[Organization].[Last_Updated] AS [LastUpdated], [Standards].[dbo].[Organization].[Date_Reviewed] AS [DateReviewed] FROM [Standards].[dbo].[Organization] WHERE ( ( ( [Standards].[dbo].[Organization].[ID] = @Id1))) Parameter: @Id1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 4.
Method Enter: CollectionCore.PerformAdd Entity to Add Description: Entity: Standards.EntityClasses.OrganizationEntity. ObjectID: 543fd344-149a-47f5-b82b-009a44baa8a8 PrimaryKey field: Id. Type: System.Int32. Value: 4 Index of added entity: 0 Method Exit: CollectionCore.PerformAdd Method Exit: DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery Method Exit: DataAccessAdapterBase.FetchEntityCollectionInternal(6) Method Exit: DataAccessAdapterBase.FetchEntityCollection(5) Method Enter: DataAccessAdapterBase.CloseConnection Method Exit: DataAccessAdapterBase.CloseConnection
Joined: 13-Jan-2006
Just discovered that if a control is declared directly within the EditItemTemplate tags of a FormView then my code WORKS! If the same control (and the field it is bound to) are declared in an ASCX file that is, in turn, placed within the FormView's EditItemTemplate, then things don't work (no items to update as per llblgen diagnostic message).
See my reply to similar post at http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7694&StartAtMessage=0�
Joined: 17-Aug-2003
I explained it here: http://www.llblgen.com/tinyforum/GotoMessage.aspx?MessageID=55721&ThreadID=7694