usercontrol, databind and updating a object data source

J

Joe

I have a user control that is in a FormView using an ObjectDataSource. When
the page renders the form correctly displays the data from the data source.
When I then change data and hit update, my update method gets called, but the
data is unchanged.

aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestObjectWeb._Default" %>

<%@ Register Src="WebUserControl1.ascx" TagName="WebUserControl1"
TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestObjectWeb.test"
SelectMethod="GetTests" UpdateMethod="UpdateTest"
TypeName="TestObjectWeb.TestContainer"
OldValuesParameterFormatString="old"
ConflictDetection="CompareAllValues"></asp:ObjectDataSource>

</div>
<asp:FormView ID="FormView1" runat="server"
DataSourceID="ObjectDataSource1" DefaultMode="Edit">
<EditItemTemplate>
<uc1:WebUserControl1 id="WebUserControl1_1" runat="server" >
</uc1:WebUserControl1>
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
</asp:FormView>
</form>
</body>
</html>

object data source code
namespace TestObjectWeb
{
public class TestContainer
{
private List<Test> _tests = new List<Test>();

public TestContainer()
{
_tests.Add(new Test());
}

public List<Test> GetTests()
{
return _tests;
}

public void UpdateTest(Test current, Test old)
{
}
}
}


data object code
namespace TestObjectWeb
{
public class Test
{
private string _name = "Joe";

public Test()
{
}

public string Name
{
get { return _name; }
set { _name = value; }
}
}
}


ascx code
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="WebUserControl1.ascx.cs" Inherits="TestObjectWeb.WebUserControl1"
%>
Name:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top