ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject NPetshop.Web.UserControls.Accounts.AddressUI.ascx.cs
Date Thu, 23 Jun 2005 16:50:09 GMT
Gilles, I like the idea extracting the user interface elements of
add/edit UserControls into a UI-UserControl:


I'm curious why the class isn't implemented like this:

 public Address PopulateAddress(Address address)
  address.FirstName = txtFirstName.Text;
  address.LastName = txtLastName.Text;
  address.Address1 = txtAddress1.Text;
  address.Address2 = txtAddress2.Text;
  address.City = txtCity.Text;
  address.Zip = txtZip.Text;
  address.State = listState.SelectedItem.Value;
  address.Country = listCountry.SelectedItem.Value;	
  address.Phone = txtPhone.Text;
  return address;

 public Address Address
    return PopulateAddress(new Address());
   txtFirstName.Text = value.FirstName;
   txtLastName.Text = value.LastName;
   txtAddress1.Text = value.Address1;
   txtAddress2.Text = value.Address2;
   txtCity.Text = value.City;
   txtZip.Text = value.Zip;
   SetSelectedItem(listState, value.State);
   SetSelectedItem(listCountry, value.Country);
   txtPhone.Text = value.Phone;

That would allow for an existing instance of Address to be populated
with values from the UI-UserControl if the UI-UserControl did not set
all the values. Let's assume the Address object has additional
properties like AddressId and ZipCodePlusFour (i.e. 90210-4554) that
for whatever reason aren't present in the UI UserControl. 

 private void btnSubmit_Click(object sender, EventArgs e)
  // AccountId and ZipCodePlusFour are populated
  Account account = GetAccountByAccountId(3);

  // get updated values for FirstName, LastName, etc.


I think that would make the UserControls more self-contained and not
have them rely on addtional values coming from an outside context.

- Ron

View raw message