我正在尝试访问中的电子邮件地址,DetailsView
但收到此错误:
Null Reference Exception was unhandled by user code
这就是我的代码中的内容:
TextBox EmailAddress = this.DetailsView1.FindControl("Email") as TextBox;
string myemail = EmailAddress.Text;
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["fromEmailAddress"]);
mailMessage.To.Add(new System.Net.Mail.MailAddress("myemail")); //ERROR
所以,代码停在这一行并得到我提到的错误:
mailMessage.To.Add(new System.Net.Mail.MailAddress("myemail"));