Currently, ASP. NET data binding is one-way, that is, allows developers to help set the data model to the page control display, when submitting a form, the page control value must be bound to the data model again. Everyone does not like to write such code.
With custom features, Spring. Web provides two-way binding between controls and data models, reducing the amount of code.
Bidirectional binding is convenient to use, but the Page class must inherit from the Spring. Web. UI. Page class.
Public class UserRegistration: Spring. Web. UI. Page
{
[Binding ("Text", "UserInfo. Email")]
Protected TextBox email;
//......
// This attribute is the data model.
Private User m_User;
Public User UserInfo
{
Get {return m_User ;}
Set {m_User = value ;}
}
}
The Binding feature has the optional parameter OneWay (the third parameter). If it is true, it degrades to one-way Binding, that is, model data is no longer updated, it is particularly useful for read-only data or read-only data obtained through computation. Another optional parameter is Format, which is used to specify the display Format of the bound value. It is usually used in combination with OneWay. It provides a date or value custom Format and supports Format expressions supported by the String. Format method.
Type conversion. Spring. the Web tries to convert data. If the Format parameter is specified. the Web will use this parameter to convert the data model value to String. Otherwise, use. NET type conversion mechanism.
Data Binding event. The base page class of Spring. Web adds two events to the lifecycle of the. NET page: DataBound and DataUnbound. The DataBound event is triggered after the control value is updated before the PreRender event. The event sequence is Load> DataBound> PreRender. This is suitable for modifying the data model in the Load event processing code, which can be reflected in the control. The DataUnbound event is triggered after the data model is updated. After the Load event, it is sent back.
Reference: spring-net-reference.pdf.
Unfortunately, the test was not successful when Spring. NET 1.1 Preview 2 was used ,. I will continue to follow up and the new version may solve the problem.