0

I have up to 5 textboxes that I need to populate with email addresses from a semicolon delimited list. I am getting a NullReferenceException error:

The text box IDs are: "txtContactEmail1", "txtContactEmail2", etc.

var _propinfo = new Upsell().RetrievePropertyInfo(strRatpropid);
strCurrency = _propinfo.currency;
strEmailList = _propinfo.ContactEmail;

string[] emails = Regex.Split(strEmailList, ";");

if (emails.Length > 0) {

    foreach (string email_loopVariable in emails) {

        if (email_loopVariable != "None Available" || email_loopVariable != "")      {
            for (int i = 1; i <= 5; i++) {

                TextBox t = (TextBox)FindControl("txtContactEmail" + (i)) as TextBox;

                t.Text = email_loopVariable;

            }
        }
    }
}

This is the line where I get the exception t.Text = email_loopVariable;

The strEmailList looks something like this:

"tsmith@myco.com;mjones@myco.com;bharris@myco.com;"

Thanks, in advance for any help I can get with this.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
T Cannon
  • 29
  • 6
  • 1
    And apart from the obvious solution, also confront whoever thought it a good idea to put such a mess in the database. It is utter nonsense to put more than one field in a single database field. – oerkelens Jul 10 '17 at 16:46
  • I agree, but inherited this. – T Cannon Jul 10 '17 at 17:36

0 Answers0