RSS 2.0
Sign In
# Sunday, July 11, 2010

It does not matter that DataBindExtender looks not usual in the ASP.NET. It turns to be so handy that built-in data binding is not considered to be an option.

After a short try, you uderstand that people tried very hard and have invented many controls and methods like ObjectDataSource, FormView, Eval(), and Bind() with outcome, which is very specific and limited.

In contrast DataBindExtender performs:

  • Two or one way data binding of any business data property to any control property;
  • Converts value before it's passed to the control, or into the business data;
  • Validates the value.

See an example:

<asp:TextBox id=Field8 EnableViewState="false" runat="server"></asp:TextBox>
<bphx:DataBindExtender runat='server'
  DataSource='<%# Import.ClearingMemberFirm %>'
  Converter='<%# Converters.AsString("XXXXX", false) %>'
  Validator='<%# (extender, value) => Functions.CheckID(value as string) %>'/>

Here, we beside a regualar two way data binding of a property Import.ClearingMemberFirm.Id to a property Field8.Text, format (parse) Converters.AsString("XXXXX", false), and finally validate an input value with a lambda function (extender, value) => Functions.CheckID(value as string).

DataBindExtender works also well in template controls like asp:Repeater, asp:GridView, and so on. Having your business data available, you may reduce a size of the ViewState with EnableViewState='false'. This way DataBindExtender approaches page development to a pattern called MVC.

Recently, we have found that it's also useful to have a way to run a javascript during the page load (e.g. you want to attach some client side event, or register a component). DataBindExtender provides this with OnClientInit property, which is a javascript to run on a client, where this refers to a DOM element:

... OnClientInit='$addHandler(this, "change", function() { handleEvent(event, "Field8"); } );'/>

allows us to attach onchange javascript event to the asp:TextBox.

So, meantime we're very satisfied with what we can achieve with DataBindExtender. It's more than JSF allows, and much more stronger and neater to what ASP.NET has provided.

The sources can be found at DataBindExtender.cs

Sunday, July 11, 2010 7:07:03 AM UTC  #    Comments [4] -
ASP.NET | Thinking aloud | Tips and tricks
Sunday, January 30, 2011 6:43:46 AM UTC
Great solution. For yet another option for two-way data binding in - this time with a WPF like syntax - see the following codeproject article:
Sam Shiles
Sunday, January 30, 2011 9:09:22 AM UTC

that's also a great solution. And as other solutions it has strong and weak sides.

From one hand it's compact, but on the other's it's not a general enough to accomodate complex bindings.

Our solution was a consequence of jsf to transition so its goal was to support arbitrary databindings, e.g. two way databinding to an expression "instance1.instance2[index].property".
Thursday, May 3, 2012 11:30:52 PM UTC

This looks like a great solution to the two-way data binding problem in ASP.Net. It seems very simple and elegant. I have downloaded your code and have tried it, but unfortunately I cannot seem to get the two-way binding to work within a Repeater.

I have a Repeater that has an ItemTemplate which contains a TextBox. I bind the repeater to a List of custom Person objects. Person contains one public string property called Name. Now I want to bind the TextBox.Text property of the ItemTemplate to the Person.Name property, so I bind it to Container.DataItem.Name. This worked for one-way binding: when I populate my List with Person objects, I see them in my Repeater, but when I type into the TextBox, it does not write the value into the Person object on the server.

Do you have any code samples for using your DataBindExtender with two-way data binding in this situation?

Friday, May 4, 2012 4:21:38 AM UTC
Hello Philipp,

In fact we have used DataBindExtender in the repeater, and it worked properly.

Do you have any simple demo project to show this problem, which you could send to the <contact at>?

We could check the reason and add it to the examples.

Said this, at present, we prefer more radical approach to the two-way databinding. If it's a new project then you may consider using technologies like jqueryui + jsview + jqgrid, or even better kendoui.

These are javascript ui frameworks, which we think is the right way to build web application, and a server side would contain just web services.
Comments are closed.
<May 2024>
Total Posts: 387
This Year: 3
This Month: 0
This Week: 0
Comments: 1064
Locations of visitors to this page
The opinions expressed herein are our own personal opinions and do not represent our employer's view in anyway.

© 2024, Nesterovsky bros
All Content © 2024, Nesterovsky bros
DasBlog theme 'Business' created by Christoph De Baene (delarou)