I found a way to “bind” objects to a web user control so that you don’t have to do this:
Address a = new Address(….);
This.txtLine1.Text = a.Line1;
This.txtLine2.Text = a.Line2;
Instead you can just do this:
UserControl.LoadData(a);
Then in the user control you have this:
Public void LoadData(Address a)
{
FormBinding.BindObjectToControls(a,this);
}
You can also retrieve the fields once the user has made changes:
FormBinding.BindControlstoObject(a,this);
It uses reflection. It requires that the controls on the form be named the same as the properties of your object. This actually makes the system very easy to read since your object properties, database fields, stored procedure variables and controls all have the same names.
Here is the original source.
I’ve used this in two separate projects and it has worked very well. If you combine it with code generation then you really realize some definite time savings with little (if any) performance penalty. See the link for the article for more info.