Welcome Guest! To enable all features please Login or Register.



How to bind an ASP.NET control to a Xomega Data Property
#1 Posted : Monday, September 24, 2012 7:10:09 PM(UTC)

You can specify a binding for an ASP.NETcontrol to a data property of a Xomega data object directly in the ASPX file. The data object serves as a view model for your form. You can call a Xomega method to bind the data object to the view, which will make the control automatically bound to the corresponding data property. This will allow Xomega Framework to keep the content of the control (such as the value or a list of values) as well as the control's state (e.g. visibility, editability, etc.) in sync with that of the data property.

In order to specify a property binding on a control, you can perform the following steps.
  1. Add an attribute Property to the XML element of the control and set its value to the name of the corresponding data property in the data object. To allow compiler validations after renaming a data property, you can bind the attribute value to a static string constant declared on your data object for the property name, for example Property="<%# ContactObject.FirstName %>".
  2. If you want to bind to a data property that is defined on a child object of the current context object, then you can set the ChildObject attribute to indicate a child object's name or a dot-delimited path to it. As described above, you can bind it to a static string constant to allow compiler checks after refactoring.
  3. Optionally set the LabelID attribute to the ID of the label element associated with this control. This will allow Xomega Framework to show or hide the label along with the control and possibly highlight the label for required properties.
  4. If you were using static constants, then make sure that in your code behind you data bind your controls to resolve those constants before binding to the data object, e.g. pnlMain.DataBind();
  5. Bind the encapsulating panel to your data object using the WebUtil.BindToObject method from the Xomega.Framework.Web namespace, e.g. WebUtil.BindToObject(pnlMain, obj);

The following XAML snippet demonstrates these steps.
<asp:Label runat="server" ID="lblFirstName" CssClass="label" Text="First Name:"/>
<asp:TextBox runat="server" LabelID="lblFirstName" ID="ctlFirstName"
             Property="<%# ContactObject.FirstName %>"
             ChildObject="<%# EmployeeObject.Contact %>"/>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.