My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Resolving Paths To Server Relative Paths in .NET Code
- Getting the Client IP Address in ASP.NET Core
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Back to Basics: Rewriting a URL in ASP.NET Core
The Voices of Reason
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
Keep it up,
Doug
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
Pete
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
http://msdn.microsoft.com/msdnmag/issues/06/12/ExtendASPNET/default.aspx?loc=en
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
About time MSDN Mag recognized your talents!
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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).
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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?
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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...
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
Posted here: http://www.west-wind.com/wwThreads/default.asp?Thread=1Z8082EY6&MsgId=1Z8082EY7
# 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!
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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...
# 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...
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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?
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
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).
# re: My first MSDN Article: A Two-way DataBinding Extender Control for ASP.NET
Cheers, Pieter