I’m trying to access the email address in the DetailsView but getting this error:
Null Reference Exception was unhandled by user code
This is what I have in my 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
So, the code is stopping at this line and getting the error I mentioned:
mailMessage.To.Add(new System.Net.Mail.MailAddress("myemail"));
I can’t help but notice that “myemail” in your code is in quotes:
try changing it to the following maybe?
referencing
Also, use the debugger