Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs
Contact   •   Articles   •   Products   •   Support   •   Search
Ad-free experience sponsored by:
ASPOSE - the market leader of .NET and Java APIs for file formats – natively work with DOCX, XLSX, PPT, PDF, images and more

My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET


:P
On this page:

So I was walking through the trade show here at the Connections conference today and ran by the MSDN booth and there it was: The December issue of MSDN Magazine, and in it my first article for the magazine. Woo hoo. It’s in the December issue and it’s about building the two-way databinding control for ASP.NET, I was talking about off and on a few months ago here on the blog.

 

I wrote about two-way databinding a long while back for ASP.NET 1.1 using custom controls that extend existing controls and provide easy two-way databinding semantics for simple control binding, along with an integrated mechanism for displaying binding, validation and business rule validation errors.

 

This new article uses the same overall concept but rather than requiring subclassing to extend controls with databinding semantics the article and accompanying control handle this by creating a single extender control that can sit on a form and essentially extend ANY control on the page with the a DataBindingItem. You can bind to ADO objects like DataRows/DataTables or to any object including entity objects.

 

It took me a while to get something to MSDN that would actually get published, so I’m excited something finally made it through… It’s in the magazine now, and should show up on the MSDN site in a few days or so…

 

Check it out…

 

[updated 11/15/2006]

The article and download can be found here:

http://msdn.microsoft.com/msdnmag/issues/06/12/ExtendASPNET/default.aspx?loc=en

If you would like to discuss or ask questions about this article in detail you can post a message on our message board here:

http://www.west-wind.com/wwthreads/default.asp?forum=White+Papers

 

Posted in ASP.NET  DataBinding  

The Voices of Reason


 

# DotNetSlackers: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET


Pieter Siegers
November 09, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Hey Rick, that is great news! Congrats!

Cheers, Pieter

ravescar
November 09, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

long time reader, and Gratz!

Doug Osborne
November 13, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Great job - I had used your original article on databinding in our framework at InfoMC - I can't believe you hadn't had an article published in MSDN previously!

Keep it up,
Doug

Peter Bromberg
November 13, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Excellent work, Rick. Kudos on making the Mag! I just skimmed through the article and the class diagram tells all.
Pete

Rick Strahl
November 16, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

The article and source code are now online on MSDN:

http://msdn.microsoft.com/msdnmag/issues/06/12/ExtendASPNET/default.aspx?loc=en

Haacked
November 16, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

I read the article and this is really great stuff! I think it'll really come in handy in Subtext!

Alex Feldstein
November 17, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Well done Rick! Great article, one that I can put to use immediately.
About time MSDN Mag recognized your talents!

Craig Neuwirt
November 30, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Fantastic article Rick. Extenders are so clean and elegant. I was wondering if there
is a way to utilize (or extend) this data binder to bind/unbind lists of objects. As you
pointed out, the GridView support using <%# Bind() %> with the DataSource is quite
limiting. It would be great to able to bind/unbind a GridView to a list of business objects
on the page. Is this a possibility?

thanks,
craig

Rick Strahl
November 30, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Craig - how would you have this work?

I've thought about this before but couldn't really see a way that this could be easily done. The binding that happens for list based bindings are managed internally by the control so there are no good ways to hook up the bindings in a way that would be easy and certainly not declarative (it's possible via code).

Ben Scott
December 17, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Great article Rick!

On Craig's comment - I'm facing the same problem at the moment. My approach was going to be something along the lines of a CustomObjectDataSource control that would provide multiple CustomObjectDataSourceViews for the list based types. The idea is to use a business object as the "Data Source" (set as a page property) in a disconnected scenario, and have the custom data source control manipulate the business object.

You would obviously need to control the initial retrieval and any updates across the wire at the page level, but you should be able to take advantage of the out of the box controls like FormView and GridView e.t.c provided that all the bindings occur from a single view.

Do you think this approach would work?

Rick Strahl
December 17, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Hi Ben - I guess I'm not sure exactly what you want to accomplish. This mechanism is meant for simple databinding which means binding a single value. The control can be used at any container level too, which means in theory you could re-bind the data at each level of the iterations in list controls and bind it to the dataview fields. That would work fine since the databinder needs some concrete property or ADO.NET field to bind to this could potentially make databinding easier in those scenarios because you could directly talk to your business objects rather than through the DataView...

But I'm not sure if this worth the hassle. What are you really gaining by doing this? These are scenarios where FormView and DetailsView actually work well with. It's the standard single control binding in ASP.NET that's lacking and that's really what this control addresses.

Maybe I'm not understanding this correctly. If you want to elaborate post a message on the message board (in the above link) and maybe provide more detail and a pseudo code sample...

Ben Scott
December 28, 2006

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET


Winston Fassett
January 30, 2007

# extender!

The Google ad results were really great when I searched your blog for "extender".

This was a very timely article. Just last week I had tried to use IExtenderProvider on a web control I was developing, and I gave up and went with a collection of extension objects. I can't wait to try out your approach!

Rick Strahl's Web Log
July 12, 2007

# Rick Strahl's Web Log


Mark Stewart
October 08, 2007

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Rick,

I ran across your control and was impressed with the logic and value of the idea.
I have tried to use it and have run into a problem with GUID values.

If I use GUIDs as the DataValueField in a DropDownList, I can bind without a problem, but when I call Unbind, it fails and I get validation errors like "Invalid Format for ...".

Is this a bug, or am I just doing something wrong?

Thanks...

Mark Stewart
October 08, 2007

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET


Rick,

Sorry for the lazy question in the previous post. I traced the code and found the bug in
the Unbind(Control WebPage) method of the wwDataBindingItem:

I added this code to the list of data types and now everything works fine.

else if (typBindingSource == typeof(System.Guid))
{
AssignedValue = new Guid(ControlValue.ToString());
}

Thanks...

Vitaly
November 22, 2007

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Hi Rick!
I'm using your Databind control with my custom business entity and without any Datasets/Datatables etc. just "Pure objects". My entity has a property
Operation with enum type Operations
public class MyEntity
{
  Operations _Operation;
...
 public Operations CurrentOperation
 {
    get{ return _Operation;}
 }
....
}

, but I didn't find the way to bind enum Operations to DropDownList in ASP.NET 2.0

all what i have is showing current value of the property in DropDownList.
Could you please give me a hint how to do this, or it's completely impossible?

Arthur Nesterovsky
August 02, 2010

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Hi Rick,

a good and actual yet article. It inspired us to create our solution for two way databinding in ASP.NET 2. See http://www.nesterovsky-bros.com/weblog/CategoryView,category,ASPNET.aspx

John Burrows
December 20, 2011

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

Hi Rick

I know this is an old article but I was wondering if it still holds it's worth in .Net 4 or whether some other technology has replaced it? Reason I ask is that i use a framework which i think is based on this and I wonder if there is a better way?

John

Rick Strahl
December 21, 2011

# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET

@John - if you're using WebForms I think it's a good way to go still. I think the native databinding features in ASP.NET are weak and very odd actually in their tight coupling. The databinder allows you to separate those concerns much more easily and bind against just about anything and provides for easy error display features.

On the downside, it's a little cumbersome to set up bindings due to the limited VS extension API which isn't a full featured citizen in the VS shell.

For MVC applications the model binding mechanism is available which is quite nice actually and doesn't require much setup. If you're using the West Wind Web Toolkit there's also WebUtils.FormVarsToObject() which performs something similar and I'm building a more generic model binder at this point that can bind to and from various different kinds inputs (form vars, json etc).
 

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2019