How to retreive data from populated controls web form only

I'm populating a generic list with data from a web form and would like to just retrieve the data from propulated controls only.  I know this could be done with if statements but that seems to be rather cumbersome so I'm looking for something more elegant.

Here is the code that retrieve the data from the form and enters the contact information in my contact collection.

        Customer customer = new Customer();
        customer.FirstName = addressInfo.FirstName;
        customer.LastName = addressInfo.LastName;
        //customer.Company.Name = addressInfo.Company;
        customer.StreetAddress = addressInfo.Street;
        customer.CityName = addressInfo.City;
        customer.ProvinceName = addressInfo.Province;
        customer.PostalCode = addressInfo.PostalCode;

        customer.AddContact(new Contact(busLabel.Text, businessNumber.Text));
        customer.AddContact(new Contact(faxLabel.Text, faxNumber.Text));
        customer.AddContact(new Contact(cellLabel.Text, cellNumber.Text));
        customer.AddContact(new Contact(homeLabel.Text, homeNumber.Text));
        customer.AddContact(new Contact(emailLabel.Text, emailAddress.Text));
        customer.AddContact(new Contact(otherLabel.Text, otherContactType.Text));
        database.AddCustomer(customer);

I don't want to add a contact information unless it has data entered in the text box and would like to avoid:

if (businessNumber.Text != String.Empty)
     customer.AddContact(new Contact(busLabel.Text, businessNumber.Text));

Customer Class:

public class Customer : Person, IPerson
{
    private long id;
    private string streetAddress;
    private int cityID;
    private string cityName;
    private int provinceID;
    private string provinceName;
    private string postalCode;
    private string notes;

    private Company company;

    private List<Contact> contactNumbers = new List<Contact>();

    public Customer()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public Customer(Company company)
    {
        this.company = company;
    }

    public long ID
    {
        get { return id; }
        set { id = value; }
    }

    public Company Company
    {
        get { return company; }
        set { company = value; }
    }

    public string StreetAddress
    {
        get { return streetAddress; }
        set { streetAddress = value; }
    }

    public int CityID
    {
        get { return cityID; }
        set { cityID = value; }
    }

    public string CityName
    {
        get { return cityName; }
        set { cityName = value; }
    }

    public int ProvinceID
    {
        get { return provinceID; }
        set { provinceID = value; }
    }

    public string ProvinceName
    {
        get { return provinceName; }
        set { provinceName = value; }
    }

    public string PostalCode
    {
        get { return postalCode; }
        set { postalCode = value; }
    }

    public string Notes
    {
        get { return notes; }
        set { notes = value; }
    }

    public List<Contact> ContactNumbers
    {
        get { return contactNumbers; }
        set { contactNumbers = value; }
    }

    public void AddContact(Contact contactParam)
    {
        contactNumbers.Add(contactParam);
    }

}

Thanks
obb-taurusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
I can't think of any way to do this without checking the condition of each control.  I'm pretty certain what you're asking can't be done, or at least can't be done without a great deal more code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
obb-taurusAuthor Commented:
paulmacd,

When you said that it can't be done without a great deal more code are you referring to the utilization of if statements or is there another method to with you are referring?

Thanks
0
Paul MacDonaldDirector, Information SystemsCommented:
It seems as if you could use javascript to call codebehind when the state of a control changed.  That would require far more code than a series of IF/THEN statements though.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

ddayx10Commented:
If you add <asp:Validator> controls to your page then it should perform both client and server side validation for you...ensuring you never have to mess with all that stuff you mentioned.

http://asp.net-tutorials.com/validation/required-field-validator/

0
obb-taurusAuthor Commented:
ddayx10,

I'm not actually looking to force the user to enter contact information in each field since that is not always necessary.  What I would like to do is only call the addContact method from my customer class on form elements where the user entered data.  If any of the form elements are blank, I want to skip that element.

0
ddayx10Commented:
IC... oops

That's a pain no matter how you tackle it. You're going to write the same amount of code either way. Even if you roll through all the .addressInfo objects (because they're all the same type at that point I'm hoping) and determine which are empty, then you use some level of reflection on your Customer object properties then roll though one list matching to the other... not worth it (at least not from here).

If the addressInfo types are not all the same(string) it gets even worse.

Sry couldn't help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.