This is very very strange.
Basically, i’m using ASP.NET. What I want is to get the .Text value from a label.
Initially, the label is actually totally empty. However, after some interaction and some clicks etc, the label changes.
Now…. I want to simply access the content of that specific label…BUT….ASP.NET thinks it’s content is STILL empty.
As a test, I changed the content of the label in to something obvious like “lol”, for example.
Then I did the procedure again. Now….This time, the results for checking the contents after all of the interaction and clicks etc turned out to be “lol”…
This means that ASP isn’t keeping track of current changes. It just keeps in mind what the initial values were.
The reason why I am checking the contents is because I wish to send an email. Below is my code:
MailMessage email = new MailMessage();
email.Subject = "****";
email.To.Add(txtEmailTo.Text);
email.From = new MailAddress("****");
email.IsBodyHtml = true;
string emailBody = "<h2>Journey Details</h2><br><strong>From</strong>: %From%<br><strong>To</strong>: %To%<br><strong>Price</strong>: %Price%<br><hr><br>Kind Regards, <br><br>";
String newBody = emailBody;
newBody.Replace("%From%", lblResultsFrom.Text);
email.Body = newBody;
try
{
SMTPServer.Send(email);
}
catch (Exception ex)
{
lblError.Text = ex.ToString();
}
I managed to fix my code. The following works: