Custom Control with 2-way databinding

Last post 07-06-2009 4:31 AM by Allen Chen – MSFT. 1 replies.

Sort Posts:

  • Custom Control with 2-way databinding

    07-01-2009, 11:01 AM

    Hi All,

    I recently posted another thread in the Data Presentation Controls forum, though I think it might have got a better reponse in this forum.

    I'm building a Custom Server Control so I can reuse it throughout my site wherever it is needed. Basically it emits a HTML table with header cells on the top and left. Inside the header cells there are titles. In the future there may also be other fields. These fields should be editable.

    The data cells also contain editable information, though this time it is a dropdown list that the user can choose from.

    The control needs to initially show data that is already in the database, but then allow the user to edit and save any of the information back to the database.

    I began this project by using User Controls for their relative simplicity, but soon discovered that it is (apparently) impossible to instantiate them from a class in my App_Code folder - they have to be instantiated from a page, or another User Control. So I moved over to Custom Server Controls.

    How it works so far: starting with a table, I use a typed dataset to get the column headings from the database, iterate through them, creating a new headercell for each one. I then get the row headings in a similar way, add a new row and header cell for each one, and also add the data cells for each column. Every one of these cells is actually another Custom Control - as I create them, I set my custom properties to populate titles into textboxes, etc.

    I thought there might be a standard way of rebinding any changes I made in these textboxes back to the database, but the one reply in my other thread would suggest not. I wanted to get a second opinion from this forum.

    Perhaps the way forward is to simply add a submit button to the page, and get each of these cells to do something on postback. I've had a look at IPostBackEventHandler and IPostBackDataHandler but can't get my head around how they work. Can anyone help?

    Disco Patrick writes web applications using:

    Visual Studio 2008
    ASP.NET 3.5
    C#
    SQL Server 2008
  • Re: Custom Control with 2-way databinding

    07-06-2009, 4:31 AM
    Answer

    Hi,

    I wrote a simple project that can help you understand IPostBackDataHandler:

    http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/Understand%7C_IPostBackDataHandler%7C_lvl%7C_300.zip 

    Sincerely,
    Allen Chen
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)