Writing a custom Server Control with 2-way databinding functionality

Last post 07-01-2009 9:07 AM by Disco Patrick. 3 replies.

Sort Posts:

  • Writing a custom Server Control with 2-way databinding functionality

    06-30-2009, 11:32 AM

    Hi all,

    I'm trying to develop a custom Server Control with 2-way databinding functionality.

    I've managed to achieve 1-way databinding by following the tutorial at http://msdn.microsoft.com/en-us/library/ms366540.aspx

    However, I can't seem to find a tutorial that explains how to implement 2-way databinding.

    Can anyone point me to a tutorial, or provide an example that fits with the tutorial at the link above?

    Thanks in advance.

    Disco Patrick writes web applications using:

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

    07-01-2009, 6:50 AM

    Anybody???

    This has really got me stumped. I'm just trying to create my own control that has similar functionality to any of the ASP.NET data controls like the GridView, FormView, etc. The main difference is that my control is based on a Table. I couldn't use the Repeater as I have to repeat downwards in columns, and you can only really use the repeater to repeat sideways in a table, because of the html syntax:

    <tr> <td></td> <td></td> ...repeat... then finally </tr>


    I've tried using this custom DataBinder control: http://msdn.microsoft.com/en-us/magazine/cc163505.aspx

    ...but am currently having trouble getting it to work in a Server Control.

    I'm sure it shouldn't be this difficult... I must be missing something very basic, surely? There must be a tutorial out there that explains this... please help!

    Disco Patrick writes web applications using:

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

    07-01-2009, 9:00 AM
    Answer
    • Member
      42 point Member
    • net.ninjutsu
    • Member since 07-01-2009, 8:08 AM
    • Posts 11

    Generally there is no straight forward way of extracting values from bound control.
    If we take GridView for example when update command is triggered on every data row in the control
    it calls template method ExtractRowValues. This method internali goes through all declared columns and
    call another template method ExtractValuesFromCell. This is the place where depending of the type of the field
    value is extracted.
    Example: TemplateField - checks if its EditItemTemplate implements IBindableTemplate and it does calls ExtractValues.
        For BoundField if finds TextBox control and get it's Text property and so on.

    Basically this is the mechanism for extracting the values from bound control.

    For more details you can use Reflector and check the code for GridView for instance.

  • Re: Writing a custom Server Control with 2-way databinding functionality

    07-01-2009, 9:07 AM

    Hmm, ok.

    In a way this is good news - at least I know now that this is not standard functionality, and there is not a huge gap in my understanding of ASP.NET.

    I'm not planning on packaging this control as a product, or even using it in future projects, so for now I will probably just implement a custom solution right in the page and not worry about making it part of the control itself.

    Disco Patrick writes web applications using:

    Visual Studio 2008
    ASP.NET 3.5
    C#
    SQL Server 2008
Page 1 of 1 (4 items)