Databases Reference
In-Depth Information
example shows how this can implemented by overriding the OnLoad of the field
template:
private FieldTemplateUserControl countryFieldTemplate;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.countryFieldTemplate = this. FindOtherFieldTemplate (“Country”);
}
Having located the field template instance of the Country property, you can use it to
access the property value and store the country name in the ContextKey of the
AutoCompleteExtender , which will pass it to the GetCompletionList of the
RegionCompletionService. This needs to be done during the Data Binding stage of the
field template lifecycle when the Customer entity instance has already been retrieved from
the database during the Load stage. The next code example shows how this can be imple-
mented in the overridden OnDataBinding method:
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
string country = this.countryFieldTemplate.FieldValueEditString;
this.autoCompleteExtender.ContextKey = country;
}
Accessing Modified Field Values of Other Columns
At this point, the Region field template can display the list of regions appropriate for the
current country when the web page is first rendered for an existing Customer entity
instance. However, when the field template is used in Insert mode and the customer
entity does not exist, the country name has not been entered yet, and the list of regions
will be empty. The list will also not be updated when user changes the Country value from
its initial value. So the last challenge is to figure out how to reload the list of regions as
the Country property value changes.
Just like in a traditional ASP.NET application, you can use post-backs and event handlers
to implement code that reacts to user input. The custom Region field template needs to
respond to the change made by the user in the Country field template, which requires
accessing the TextBox control it instantiates. The next example shows an extract from the
Region_Edit field template that accomplishes this task:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var countryFieldTemplate = this.FindOtherFieldTemplate(“Country”);
var countryTextBox = (TextBox)countryFieldTemplate.DataControl;
countryTextBox.AutoPostBack = true;
 
Search WWH ::




Custom Search