I'm trying to use the ASP.NET 4.5 strongly typed model binding on multiple web user controls that are added to a single Formview inside the Edit and Item Templates so I can update the data.
i.e. I have an aspx page like this-ish
<asp:FormView ID="FormView1" runat="server"
ItemType="MyDataLayer.MyDataItem"
SelectMethod="FormView1_GetItem"
UpdateMethod="FormView1_UpdateItem"
DataKeyNames="MyDataItemID" >
<EditItemTemplate>
<asp:LinkButton Text="Update" runat="server" CommandName="Update"/>
<uc1:WebUserControl1 runat="server" id="WebUserControl1" />
<uc1:WebUserControl1 runat="server" id="WebUserControl2" />
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton Text="Edit" runat="server" CommandName="Edit" />
<uc1:WebUserControl1 runat="server" id="WebUserControl1" />
<uc1:WebUserControl1 runat="server" id="WebUserControl2" />
</ItemTemplate>
</asp:FormView>
With ascx user controls like this(simplified version)
<%@ Control Language="C#" AutoEventWireup="false"
CodeBehind="WebUserControl1.ascx.cs"
Inherits="WebApplicationTests.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# BindItem.Name%>'></asp:TextBox>
I'm able to get it to work if I move the guts of the user control to the page with the formview, but it will not work in the user control.
In other words, I want the user control fields bound to the parent page Formview data with the new "BindItem", and use the formview ItemType, so I will have a single item of data, bound to multiple controls that hold different pieces of the same item within the formview. (The project is based on a monolithic table with everything, but we want to separate the data to the user for clarity)
If there are any idea's on how to get this to work, or anyone knows why it doesn't work that would be great!