Continuing: Data binding to a CompositeControl
- From: intrader <intrader@xxxxxxx>
- Date: Sun, 25 Mar 2007 18:39:40 -0700
intrader wrote:
I am very new at using the CompositeControl or CompositeDataBoundControl and at DataBinding in generalRecently I have been reading Espositos "Introducing Microsoft® ASP.NET 2.0" section on CompositeControl and TypeDescriptor. Very worthwhile!
My requirement is that I would like to declaratively tell my control to bind to a specific instance of a class; the control then looks at the metadata held in the instance to provide the appropriate control behavior.
The syntax follows the 'standard' <tag:controlname DataSource="here I don't know what to specify" />. What I want in "here I don't know what to specify" is something like instanceName.someFieldOrProperty, where the field (property) has a metadata to describe the behavior of the field.
From within the control I would like to be able to access the field via the DataSource property.
I thought of using an event driven approach and have the control.DataBinding event execute an event handler that would take the DataSource of some container (like a panel) and figure out the metadata in the field of the data source; but, this seems overly complex.
In a nutshell, given an instance fld containing a reference to someClass.someFieldOrProperty, I would like the more direct approach of using DataSource ="fld". Is 'fld' accessible within the code of the control?
Thanks
P.S. I have been following the very good examples in the newsgroup, but I have not figured this out yet.
I am also studying a very well written article on TypeDescriptors that dwells on their archtecture: "http://blogs.msdn.com/parthopdas/archive/2006/01/03/509103.aspx". Wonderful article!
I have done some prototype coding that allows me to:
1.Use a Business Object class with properties that are attribute decorated with metadata (similar to the Enterprise Library 3.0):
public class Address:BusinessObjectBase{
[StreetAttribute]string Street{...}
[StatesAttribute]ReadOnlyNameValues States(...)
[ZipCodeAttribute]string ZipCode{...}
.
.
.
}
2.Have a panel-like pagelet control to which I attach an instance of Address myAddress (this may act like an ObjectDataSource class):
<CAFM:pagelet BO="myAddress" .../>
3. Drop a Field objects in the pagelet; the control takes care of naming appropriately for cases where the BO is within another BO or within an instance of a collection:
<CAFM:field Name="Street" />
<CAFM:field Name="States" />
<CAFM:field Name="ZipCode" />
4. They render appropriate controls containing a Title, the control displaying the value - TextBox, DropDownList, TextBox respectivelly
I have gotten to the point where the rendered code looks OK. The postback seems OK, but the naming of the controls becomes a problem if the BO is within another BO or is part of a collection; the design-time is lacking proper display of the metadata driven fields. So I am investigating TypeDescriptor driven design time modification.
I have hoped to get some dialog going on for this thread, but something must be missing in how I phrase or present the thread as no-one has picked up the thread.
Thanks for any help.
.
- References:
- Data binding to a CompositeControl
- From: intrader
- Data binding to a CompositeControl
- Prev by Date: ITemplate and ControlBuilder
- Next by Date: Re: BE-CAREFUL, YOU COULD BE A VICTIM OF SCAM OR FRAUD!!!
- Previous by thread: Data binding to a CompositeControl
- Next by thread: Re: web.config servercontrol binding problem
- Index(es):
Relevant Pages
|