usercontrol, databind and updating a object data source

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Sm9l?=

    usercontrol, databind and updating a object data source

    I have a user control that is in a FormView using an ObjectDataSourc e. 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="Def ault.aspx.cs"
    Inherits="TestO bjectWeb._Defau lt" %>

    <%@ Register Src="WebUserCon trol1.ascx" TagName="WebUse rControl1"
    TagPrefix="uc1" %>

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

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitl ed Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
    DataObjectTypeN ame="TestObject Web.test"
    SelectMethod="G etTests" UpdateMethod="U pdateTest"
    TypeName="TestO bjectWeb.TestCo ntainer"
    OldValuesParame terFormatString ="old"
    ConflictDetecti on="CompareAllV alues"></asp:ObjectDataS ource>

    </div>
    <asp:FormView ID="FormView1" runat="server"
    DataSourceID="O bjectDataSource 1" DefaultMode="Ed it">
    <EditItemTempla te>
    <uc1:WebUserCon trol1 id="WebUserCont rol1_1" runat="server" >
    </uc1:WebUserCont rol1>
    <asp:LinkButt on ID="UpdateButto n" runat="server"
    CausesValidatio n="True" CommandName="Up date"
    Text="Update">
    </asp:LinkButton>
    <asp:LinkButt on ID="UpdateCance lButton" runat="server"
    CausesValidatio n="False" CommandName="Ca ncel"
    Text="Cancel">
    </asp:LinkButton>
    </EditItemTemplat e>
    </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<TestGetTes ts()
    {
    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="Web UserControl1.as cx.cs" Inherits="TestO bjectWeb.WebUse rControl1"
    %>
    Name:
    <asp:TextBox ID="NameTextBox " runat="server" Text='<%# Bind("Name") %>'
    ></asp:TextBox>


Working...