After struggling with ASP.NET data binding we found no other way but to introduce our little extender control to address the issue.
We were trying to be minimalistic and to introduce two way data binding and to support data conversion. This way extender control (called DataBindExtender) have following page syntax:
DataBindExtender
<asp:TextBox id=TextBox1 runat="server"></asp:TextBox><cc1:DataBindExtender runat="server" DataSource="<%# Data %>" DataMember="ID" TargetControlID="TextBox1" ControlProperty="Text" />
Two way data binding is provided with DataSource object (notice data binding over this property) and a DataMember property from the one side, and TargetControlID and ControlProperty from the other side. DataBindExtender supports Converter property of type TypeConverter to support custom converters.
DataSource
DataMember
TargetControlID
ControlProperty
Converter
TypeConverter
DataBindExtender is based on AjaxControlToolkit.ExtenderControlBase class and implements System.Web.UI.IValidator. ExtenderControlBase makes implementation of extenders extremely easy, while IValidator plugs natuarally into page validation (Validate method, Validators collections, ValidationSummary control).
AjaxControlToolkit.ExtenderControlBase
System.Web.UI.IValidator
ExtenderControlBase
IValidator
Validate
Validators
ValidationSummary
The good point about extenders is that they are not visible in designer, while it exposes properties in extended control itself. The disadvantage is that it requires Ajax Control Toolkit, and also ScriptManager component of the page.
ScriptManager
To simplify the use DataBindExtender gets data from control and puts the value into data source in Validate method, and puts data into control in OnPreRender method; thus no specific action is required to perform data binding.
OnPreRender
Source for the DataBindExtender is DataBindExtender.cs.
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u