Bidirectional data binding)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.