Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Implementing Two-Way Control Binding for Web Forms : Page 6

ASP.NET's native data binding provides only one-way data binding. With a little bit of effort, it's possible to extend the native functionality and provide flexible two-way data binding and a few other simple enhancements that drastically reduce the amount of code you have to write for binding data to controls.


advertisement
Error Display
This next method creates an array of BindingErrorobjects containing information about the error. You can configure custom binding error messages by setting a binding error message on the control (see Figure 4). Otherwise, the code in Listing 7 assigns a generic error message to the property.

Reflection makes it possible to dynamically read and assign property values that were assigned at design time. You can think of it as a simple evaluation mechanism.
This array of binding errors, if any, is returned from the Unbind operation. A couple of helper methods exist to turn the array into HTML. The code for the Inventory example you saw earlier looks something like this:

... BindingError[] Errors = wwWebDataHelper.FormUnbindData(this); if (Errors != null) { this.ShowErrorMessage( wwWebDataHelper.BindingErrorsToHtml(Errors) ); return; } if (!Inventory.Save()) ...

In addition, each of the controls contains some custom code to display error information, as shown in Figure 5.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date